F.read()和F.readlines():
1 #Python读取txt 2 def Fread(): 3 print('-----read by .read()-----') 4 with open('test.txt', encoding='utf-8') as file: 5 content = file.read() 6 print('content: ', content, 'type of content: ', type(content)) #输出原P.txt type of content: <class 'str'> 7 8 def Freadlines(): 9 print('-----read by .readlines()-----') 10 with open('test.txt', encoding='utf-8') as file: 11 content = file.readlines() 12 print('content: ', content, 'type of content: ', type(content)) #输出列表,每一行为一项 type of content: <class 'list'> 13 14 if __name__ == '__main__': 15 Freadlines()
标签:__,读取,Python,content,read,file,txt,type From: https://www.cnblogs.com/0xiaoyu/p/16658345.html