Discuss / Python / 使用with最保险,避免忘记使用close()方法的尴尬

使用with最保险,避免忘记使用close()方法的尴尬

Topic source

GOGOGO-枼子

#1 Created at ... [Delete] [Delete and Lock User]

fpath = r'c:/windows/system.ini'

with open(fpath, 'r') as f: s = f.read(15) print(s)

with open(fpath, 'r') as fs: ss = fs.readlines() for x in ss: print(x)


  • 1

Reply