How to read files in python?
First, create a txt document on the desktop and enter the following content:
你好。 Hello. abcdefg 啊不错的风格
Recommendation: "Python Tutorial》
View the properties of the file and get the absolute path of the file:
D:\HintSoft\Hint-W7\Desktop
Then, the absolute path plus the file name is the absolute file name:
D:\HintSoft\Hint-W7\Desktop\新建文本文档.txt
f = open(r"D:\HintSoft\Hint-W7\Desktop\新建文本文档.txt",'r')
f = open(r"D:\HintSoft\Hint-W7\Desktop\新建文本文档.txt",'r') s=f.read() print(s)
f = open(r"D:\HintSoft\Hint-W7\Desktop\新建文本文档.txt",'r') s=f.read(6) print(s)
The above is the detailed content of How to read files in python. For more information, please follow other related articles on the PHP Chinese website!