os.path.isfile

eryk sun eryksun at gmail.com
Fri Feb 10 22:01:23 EST 2017


On Fri, Feb 10, 2017 at 9:09 PM, Vincent Vande Vyvre
<vincent.vande.vyvre at telenet.be> wrote:
> Le 10/02/17 à 22:03, Vincent Vande Vyvre a écrit :
>> Le 10/02/17 à 21:36, Peter Otten a écrit :
>>> Vincent Vande Vyvre wrote:
>>>> Le 10/02/17 à 19:11, eproser at gmail.com a écrit :
>>>>>
>>>>> Python 3.5.2
>>>>>
>>>>> Windows 10
>>>>>
>>>>> os.path.isfile() no recognise file with double dot?
>>>>>
>>>>> eg. match.cpython-35.pyc
>>>>>
>>>> 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 ?
>>>
>>> No idea in the case of the OP -- on Windows a string literal containing a
>>> sequence like "...\t..." is always a good candidate.
>>>
>>> But you probably sneaked in a trailing newline or space -- i. e. 'twas a
>>> pasting mishap ;)
>>>
>> No, it's a copy-paste.
>>
>> No trailing newline.
>>
> OooPs, no newline but just a space.

It works for me in Windows 10:

    >>> sys.version_info[:3], sys.getwindowsversion()[:2]
    ((3, 5, 2), (10, 0))

    >>> os.path.isfile(r'__pycache__\match.cpython-35.pyc')
    True

We know the problem isn't a typo with trailing spaces or dots, since
Windows strips them from the last path component to be compatible with
MS-DOS (which had a weak excuse to cut corners because it was written
in 8086 assembly):

    >>> os.path.isfile(r'__pycache__\match.cpython-35.pyc ... ')
    True

Using a file with a name like that in Windows requires a
fully-qualified path prefixed by \\?\ to bypass DOS compatibility
processing.



More information about the Python-list mailing list