0
私はそれを実行しようとすると、これはUTF-8エラーopen()関数
Traceback (most recent call last):
File "C:\Python27\read.py", line 6, in <module>
read_text()
File "C:\Python27\read.py", line 2, in read_text
quotes = open("‪C:/Users/Matteo/Desktop/quotes.txt")
IOError: [Errno 22] invalid mode ('r') or filename: '\xe2\x80\xaaC:/Users /Matteo/Desktop/quotes.txt'
を思われるものである
def read_text():
quotes = open("C:/Users/Matteo/Desktop/quotes.txt")
contents_of_file = quotes.read()
print(contents_of_file)
quotes.close()
read_text()
だけ開き、ファイルを読み込む
Pythonで簡単なコードを書きましたインターネットで検索したところ、IDLEはC、\ xe2 \ x80 \ xaaの前にUnicode文字を認識していることが理解できました。これは「左から右への組み込み」です。私はこれとは何か、私のコードからどのように削除するのか分かりません。
ソースコードファイルの先頭に '# - * - coding:utf-8 - * - '(または他のエンコーディング)行がありますか?私はそれが 'utf-8'であるべきだと思う。 –
@AndrewCherevatkin IDLEはその文字列を追加するように頼んだが、何も変わらなかった。 –
@melpomeneああ、私はそれをして、今、うまくいく。回答? –