|
本帖最后由 巡山大大大王 于 2018-4-16 15:31 编辑
def main():
file=open("F:\python practice\第六周 文件与字典\phone number.txt","r")
print(file.read())
file.close()
main()
"""我要学Python
我要学Python
我要学Python
我要学Python"""
def main():
file=open("F:\python practice\第六周 文件与字典\phone number.txt","r")
for line in file:
line=file.read()
print(line)
file.close()
main()
"""我要学Python
我要学Python
我要学Python"""
上面一个遍历程序在读取文件内容时,为啥不会读取第一行呢?而第一个程序只要求读取时为啥可以读取全部文件内容呢?求大神解答
|
|