+ -
当前位置:首页 → 问答吧 → vim编辑python编码问题

vim编辑python编码问题

时间:2011-08-11

来源:互联网

Python code

# -*-coding:utf-8-*-
inFile = open(r'f:\make\测试\1.txt','r')
for line in inFile:
    print line



在vim中设置 set fileencoding=cp936 可以正常运行 
但设成 fileencoding=utf-8运行时路径为乱码报错

cmd.exe /c python 2.py
Traceback (most recent call last):
  File "2.py", line 2, in <module>
  inFile = open(r'f:\make\娴嬭瘯\1.txt','r')
IOError: [Errno 2] No such file or directory: 'f:\\make\\\xe6\xb5\x8b\xe8\xaf\x9
5\\1.txt'
shell returned 1
Hit any key to close this window...

大家知道怎么回事吗?

作者: kithon   发布时间: 2011-08-11

Python code
# -*-coding:utf-8-*-
inFile = open(r'f:\make\测试\1.txt'.decode('utf-8'), 'r')
for line in inFile:
    print line


试试

作者: Waistcoat23   发布时间: 2011-08-11

open识别不了编码,这样,inFile = open(ur'f:\测试\1.txt', 'r');
或者象LS一样解码

作者: I_NBFA   发布时间: 2011-08-11