|
读取文档的时候,open 函数返回一个文件对象,当对这个文件对象进行for循环赋值之后就可以读取文件的内容;但是简单的将open返回的对象进行赋值的之后得到的却还是一个文件对象;
请教给位大牛:
简答的赋值与for 的循环赋值之间有什么本质的区别?
f=open(r"e:\python01\01.txt","r")
i=0
for x in f:
print(x)
print(x,f)
a=f
print(a)
显示结果:
hello world!
hello world! <_io.TextIOWrapper name='e:\\python01\\01.txt' mode='r' encoding='cp936'>
<_io.TextIOWrapper name='e:\\python01\\01.txt' mode='r' encoding='cp936'>
>>>
|
|