os.path.exists not working properly on Python CLI -



os.path.exists not working properly on Python CLI -

i've python 2.5.x on windows 7 machine.

os.path.exists('c:') # returns true os.path.exists('c:\users') # returns true os.path.exists('c:\users\alpha') # returns false, when alpha user on machine

i've given read/write permissions cli i'm using. possible reason ?

inside quotes, '\' escapes next character; see reference on string literals. either double backslashes like:

os.path.exists('c:\\users\\alpha')

to escape backslashes themselves, utilize forwards slashes path separators michael suggests, or utilize "raw strings":

os.path.exists(r'c:\users\alpha')

the leading r cause python not treat backslashes escape characters. that's favorite solution dealing windows pathnames because still people expect them to.

python python-module

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -