path="C:\\Users\\ming\\Desktop\\pydata-book-2nd-edition\\examples\\segismundo.txt"
# 建立新的tep.txt文件并将其放在桌面上
with open('C:\\Users\\ming\\Desktop\\tep.txt','w') as hen:
hen.writelines(x for x in open(path) if len(x)>1)
# 读取每一行
with open('tep.txt') as f:
lines=f.readlines()
print(lines)
# 读取十个字
with open(path) as f:
chars=f.read(10)
print(chars)
with open(path,'rb') as f:
data=f.read(10)
print(data)
# 解码
print(data.decode('utf8'))



被折叠的 条评论
为什么被折叠?



