os.path.isfile

Steve D'Aprano steve+python at pearwood.info
Sat Feb 11 22:52:09 EST 2017


On Sat, 11 Feb 2017 05:11 am, eproser at gmail.com wrote:

> Hello NG
> 
> Python 3.5.2
> 
> Windows 10
> 
> os.path.isfile() no recognise file with double dot?
> 
> eg. match.cpython-35.pyc



I doubt that very much. I expect you are probably writing something like
this:


path = 'My Documents\testing\path\match.cpython-35.pyc'
os.path.isfile(path)

and not realising that you have a TAB character in your string from the \t,
or something similar.

In Python, you should always use forward slashes for paths, even on Windows.

path = 'My Documents/testing/path/match.cpython-35.pyc'

Try printing the repr() of your path.





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list