We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents da93a3b + ffebb22 commit cde2d34Copy full SHA for cde2d34
python_base.py
@@ -320,6 +320,10 @@ def __missing__(self, key):
320
fp.truncate([size]) # 把文件裁成规定的大小,默认的是裁到当前文件操作标记的位置。
321
for line in open('data'):
322
print(line) # 使用for语句,比较适用于打开比较大的文件
323
+ with open('data') as file:
324
+ print(file.readline()) # 使用with语句,可以保证文件关闭
325
326
+ lines = file.readlines() # 一次读入文件所有行,并关闭文件
327
open('f.txt', encoding = 'latin-1') # Python3.x Unicode文本文件
328
open('f.bin', 'rb') # Python3.x 二进制bytes文件
329
# 文件对象还有相应的属性:buffer closed encoding errors line_buffering name newlines等
0 commit comments