python 读文本文件

#!/usr/bin/python3
print("h");
f=open("x.txt","r")
print(f)
line=f.readline()
print(line)
for c in line:
    print(c)
print("finshed")
f.close()

文本文件内容

hello I  am line one
i am line two

输出

h
<_io.TextIOWrapper name='x.txt' mode='r' encoding='UTF-8'>
hello I  am line one

h
e
l
l
o
 
I
 
 
a
m
 
l
i
n
e
 
o
n
e


finshed

https://www.runoob.com/python3/python3-file-methods.html

原文地址:https://www.cnblogs.com/feipeng8848/p/12810069.html