Python 在给定的代码中,我首先放置的块顺序返回结果,而我放置的块[在desc中继续]
[continuation]-second将结果返回为零,为什么以及如何使两个读取函数使用相同的文件名 代码:Python 在给定的代码中,我首先放置的块顺序返回结果,而我放置的块[在desc中继续],python,python-3.x,file,readlines,Python,Python 3.x,File,Readlines,[continuation]-second将结果返回为零,为什么以及如何使两个读取函数使用相同的文件名 代码: myfile=open(r'C:\Users\win8\Documents\Cs Record\trust.txt','r') **#number of lines in the file:** r2=myfile.readlines() nol=len(r2) print('The number of lines in trust.txt is',nol) **#si
myfile=open(r'C:\Users\win8\Documents\Cs Record\trust.txt','r')
**#number of lines in the file:**
r2=myfile.readlines()
nol=len(r2)
print('The number of lines in trust.txt is',nol)
**#size of the file:**
r1=myfile.read()
sof=len(r1)
print('The size of trust.txt is',sof,'bytes')
myfile.close()
使用
myfile.seek(0)
还是更好地利用
with open('file.txt') as f:
read_data = f.read()
# file is closed now