error in os.chdir

Steven D'Aprano steve+comp.lang.python at
Sun Jul 1 01:19:59 EDT 2018

On Sun, 01 Jul 2018 02:22:41 +0000, eryk sun wrote:

> I use the native API a lot, so for me registry and file paths are just
> paths. It's only the Windows API that separates the two and only the
> Windows API that allows forward slash as a path separator in file paths.

Not being a Windows user, I don't actually understand how this works.

I gather that there's a low-level "native API" (DOS?) used by the Windows 
OS, and a higher level "Windows API" used by, er, another part of the API.

But I'm not sure how that interacts with Python.

The way I see it, when we say "always use forward slashes for file 
paths", we're talking about Python level file commands like open(), 
os.path.exists, etc.

If you're using Python to directly call Windows external programs, say 
"os.system('dir')", then of course you have to follow the Windows rules. 
(The same applies to Unix/Linux systems too, of course.) But while you're 
using Python to manipulate files, you should use Python rules, and that 
is "always use forward slashes".

Is that reasonable?

Under what circumstances would a user calling open(pathname) in Python 
need to care about backslashes?

Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

More information about the Python-list mailing list