开发者

Python: error IOError: [Errno2] bad interpretation of file or directory

开发者 https://www.devze.com 2023-02-25 09:15 出处:网络
I\'m try trying to read an csv file and the interpreter return a bad directory by duplicating the \\ > result = [[urlparse(u).netloc] for u in file (\'S:\\Dev\\Python\\BDDtest.csv\')]

I'm try trying to read an csv file and the interpreter return a bad directory by duplicating the \

> result = [[urlparse(u).netloc] for u in file ('S:\Dev\Python\BDDtest.csv')]

>>IOError: [Errno 2] No such file o开发者_JAVA百科r directory: 'S:\\\Dev\\\Python\\\BDDtest.csv'

When I put it in a ufile ='S:\Dev\Python\BDDtest.csv' and print it the result is correctly interpreted

but when I try a

> result = [[urlparse(u).netloc] for u in file (ufile)]

It return the same error...

Anyone as a fix or an explaination


Maybe a hack with os.path.abspath will help?

import os
result = [[urlparse(u).netloc] for u in 
          file(os.path.abspath('S:\Dev\Python\BDDtest.csv'))]

You can also try using ntpath explicitly:

import ntpath
result = [[urlparse(u).netloc] for u in 
          file(ntpath.abspath('S:\Dev\Python\BDDtest.csv'))]


You can try replace \ to /

0

精彩评论

暂无评论...
验证码 换一张
取 消