Python: error IOError: [Errno2] bad interpretation of file or directory
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 /
精彩评论