On Fri, May 22, 2015 at 12:14 AM, Grant Edwards <invalid@invalid.invalid> wrote: > On 2015-05-21, Steven D'Aprano <steve+comp.lang.pyt...@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 -- https://mail.python.org/mailman/listinfo/python-list