os.path.isfile
Steve D'Aprano
steve+python at pearwood.info
Sat Feb 11 22:48:17 EST 2017
On Sat, 11 Feb 2017 06:50 am, Vincent Vande Vyvre wrote:
> Le 10/02/17 à 19:11, eproser at gmail.com a écrit :
>> Hello NG
>>
>> Python 3.5.2
>>
>> Windows 10
>>
>> os.path.isfile() no recognise file with double dot?
>>
>> eg. match.cpython-35.pyc
>>
>> Please somebody know something about that?
>>
>> Thank You in advance
>>
> Interesting, you're right.
>
> Python 3.4.3 (default, Nov 17 2016, 01:08:31)
> [GCC 4.8.4] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import os
> >>>
>
os.path.isfile('/home/vincent/oqapy-3/trunk/__pycache__/grid.cpython-34.pyc
> ')
> False
>
>
> Why ?
How do you know that file exists?
Why choose such a long file name where you risk introducing spaces or
newlines due to word-wrapping?
I cannot replicate your result using Python 3.5 on Linux:
py> path = '/tmp/spam.eggs.cheese.txt'
py> with open(path, 'w') as f:
... f.write('something')
...
9
py> import os
py> print(os.path.isfile(path))
True
I expect that you have a space at the end of the file name:
'/home/vincent/oqapy-3/trunk/__pycache__/grid.cpython-34.pyc '
instead of
'/home/vincent/oqapy-3/trunk/__pycache__/grid.cpython-34.pyc'
--
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