os.chdir

"Martin v. Löwis" martin at v.loewis.de
Sat Mar 8 09:35:22 EST 2008


>> os.chdir("~/dir1")
> 
> It is not mentioned in the documentation but I'm pretty sure os.dir() doesn't do
> tilde expansion since this is usually performed by a shell.
> 
> You should use instead:
> 
> os.chdir(os.join(os.environ['HOME'], 'dir1'))

Or

os.chdir(os.path.expanduser("~/dir1"))

Regards,
Martin



More information about the Python-list mailing list