程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python | file operation | read / write operation of text file

編輯:Python
'''
When you first read the contents of a file , Can't succeed .
Problems arise : Failed to read when the text content is Chinese , English and figures are successful .
Solution : stay open(), Add in "r",encoding='utf-8'
The specific reason ->https://blog.csdn.net/weixin_46709219/article/details/112060945
'''
# encoding='utf-8'
# f = open(' Corn poppy .txt',"r",encoding='utf-8')
# text = f.read()
# print(text)
# f.close()
# The following code also has problems at the beginning :
# stay python in '\' Will be used as escape characters ,'C:\Users\86151\Desktop\ Corn poppy · When is the spring flowers and autumn moon .txt'
# Solution : Add before the above code ‘r’, In this way, it can be read successfully
# The specific reason ->https://www.cnblogs.com/rychh/p/9743864.html
# f = open(r'C:\Users\86151\Desktop\ Corn poppy · When is the spring flowers and autumn moon .txt',encoding='utf-8')
# for line in f:
# if (len(line.strip())==0):continue
# print(line.strip())
# f.close()
f = open(r'C:\Users\86151\Desktop\ Corn poppy · When is the spring flowers and autumn moon .txt',encoding='utf-8')
lines=f.readlines()
print(lines)
f.close()

Text file reading / Write operations · Language sparrow (yuque.com)

Hee , I haven't studied for a long time

Indulge in the king Rong Yao

Feel happy , Is very empty . As time goes on, tut ...

Still have to learn a little , Come on, big pineapple


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved