0
点赞
收藏
分享

微信扫一扫

python - 7.读取文件内容


读取文件内容:

from sys import argv

script ,filename = argv

print(f"你要打开的是{filename}:")
# text = open(filename)
text = open(filename,'r', encoding='UTF-8')
content = text.read(10)
print(f"文件内容是:{content}")
text.close()

another_file = input("另一个文件名字: ")
another_text = open(another_file,'r',encoding = "utf-8")
print(another_text.read())
another_text.close()

报错了,gbk编码不能解码.

python - 7.读取文件内容_html

open的时候需要设置编码集:

python - 7.读取文件内容_python_02

在cmd里面用python读取文件内容:

python - 7.读取文件内容_html_03

python书籍:
​​​https://github.com/yidao620c/python3-cookbook/blob/master/source/index.rst​​​​​​

​​https://python3-cookbook.readthedocs.io/zh_CN/latest/​​

​​https://www.xncoding.com/2017/01/22/fullstack/readthedoc.html​​


举报

相关推荐

0 条评论