云中漫步 发表于 2017-4-22 10:51:13

python,with open

  用python的时候,会经常遇到文件数据库的open,但总会不小心忘了close
  用with open 语句就能很好的解决这个问题,它会在语句执行完后,自动执行close()



with open('./prepare_channels.txt', 'r') as f:   
for s in f:
channels.add(s.strip())
页: [1]
查看完整版本: python,with open