Find if a file existing within 1000s of folder/sub-folder - each file has a unique presence

Chris Angelico rosuav at gmail.com
Thu May 21 10:27:17 EDT 2015


On Fri, May 22, 2015 at 12:14 AM, Grant Edwards <invalid at invalid.invalid> wrote:
> On 2015-05-21, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
>
>> import glob
>> print(glob.glob("c:/abc/def/ghjmain/features/XYZ/*<filename>"))
>>
>> Don't use backslashes \ as they have special meaning to Python. Use forward
>> slashes and let Python convert them as needed.
>
> Interesting. I've never heard about this.
>
> When will Python convert them?

Actually, it won't ever bother to convert them. The Windows file
system APIs are quite happy to work with forward slashes; it's only
command-line tools (which conventionally use forward slashes to
introduce options), and not all of them, which require backslashes.

You may want to consider explicitly converting them in your own code,
prior to showing a path to a human; but even back in the 1990s, it
wasn't uncommon for cross-platform programs to mix and match - for
instance, if you unzip something into C:\Foo\Bar, you'd get output
like "Inflating C:\Foo\Bar/usr/lib/whatever". I'd have no objections
to a program using forward slashes all the way.

ChrisA



More information about the Python-list mailing list