python - 7.ファイルの内容を読み取ります

著作権:経験の声は、私は、変更パッケージスパイシーバー、およびその他のは、ソースを明記してくださいかどうかわかりません。https://blog.csdn.net/zhezhebie/article/details/89436274

ファイルの内容を読みます:

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 cmdを使ってファイルの内容を読みます:
ここに画像を挿入説明

Pythonの図書:
https://github.com/yidao620c/python3-cookbook/blob/master/source/index.rst
https://python3-cookbook.readthedocs.io/zh_CN/latest/
HTTPS://www.xncoding。コム/ 2017年1月22日/ fullstack / readthedoc.html

おすすめ

転載: blog.csdn.net/zhezhebie/article/details/89436274