关于open()返回值及打印输出的问题

来源:互联网 发布:网络女主播卸妆前后 编辑:程序博客网 时间:2024/05/19 12:16

文件file.txt的内容为

i'm your big  brother
he is a man

以下几个代码片段的运行内容分别为:

1)

file=open('file.txt','r')print(file)# <_io.TextIOWrapper name='file.txt' mode='r' encoding='cp936'> # 输出内容包括文件名,打开模式,编码方法

2)

file=open('file.txt','r')for line in file:    print(line)'''i'm your big  brotherhe is a man输出内容正确,但多了一行空白?原因未知'''

3)

file=open('file.txt','r')line=file.read()print(line)'''i'm your big  brotherhe is a man输出内容正确'''


0 0
原创粉丝点击