windows - Unusual path joining in python's os library -
i trying in windows 8.1, python v.3.4. os.path
module has join
method which, according documentation, safe way join fragments of files or folders without mixing , forward slashes. in code snippet below trying join file , folder:-
>>> photo = r"\camera\picnic.jpg" >>> folder = os.getcwd() >>> print(folder) c:\users\renae >>> path = os.path.join(folder, photo) >>> print(path) c:\camera\picnic.jpg
and boom goes dynamite. expecting path c:\users\renae\camera\picnic.jpg
. i've tried removing r
in front of photo
no results. i've tried backslashes though windows uses forward slashes made worse. result mix of , forward slashes. if remember correctly not problem in linux.
try removing initial slash.
i can't speak windows because it's been long time since working on windows, in *nix systems, starting path slash signifies root of file system. i'm guessing implementation in python (and possibly more languages) use convention on windows well. don't have windows box verify on though.
Comments
Post a Comment