0

エディター (VIM) で開いたファイルの内容を試しています。

推定値:

fileh = open( path, 'r' )
content = fileh.read()
fileh.close()

ファイルを VIM で開くと、エラーが発生します。VIM がファイルの排他ロックを保持している場合、これは理解できますが、エラー メッセージに基づいて、そうではないようです。

UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 16: ordinal not in range(128)

VIM が開いたファイルに非 ASCII 文字を書き込んでいるように思えます!

または utf-16を使用してファイルを開くとopen( path, 'r', encoding='utf-8')、うまくいかないようです (utf-8/utf-16 デコード エラーが発生します)。

どんな助けでも大歓迎です!

更新: VIM ではなく Gedit でファイルを開いた場合、この問題は発生しません。もちろん、これは修正ではないので、何が問題なのかを突き止める必要があります。

4

1 に答える 1

0

Oke, I figured it out.

The problem is not with python not being able to decode the files I am interested in, but python reading .swp files, generated by VIM. My program was not filtering the input directory correctly.

Thanks for the help though!

于 2012-05-15T19:01:16.117 に答える