IOError:[Errno 22]无效模式('r')或文件名:'E:\ x07nu \ meta.csv'

时间:2016-06-20 04:18:02

标签: windows python-2.7 backslash

IOError:[Errno 22]无效模式('r')或文件名:'E:\ x07nu \ meta.csv'

f = open("E:\anu\meta.csv","r")


for line in file:

        x = line.split(",")

        print(x[0])

3 个答案:

答案 0 :(得分:3)

\ a正在制造问题。像\ a和\ t等字符会产生这样的问题。

改为使用原始字符串:

test_file=open(r'E:\anu\meta.csv','r')

或加倍斜杠:

test_file=open('E:\\anu\meta.csv','r')

或改为使用正斜杠:

test_file=open('E:/anu/meta.csv','r')

答案 1 :(得分:0)

Try the following which does not interpret escape sequences of your path (like \a)

f = open(r"E:\anu\meta.csv","r")

答案 2 :(得分:0)

如果使用Python 2.7,请以二进制模式打开'rb'

尝试使用以下任一方法:

f = open(r'E:\anu\meta.csv','rb') as f

f = open(r'E:\\anu\\meta.csv','rb') as f