os.chdir

rbossy at jouy.inra.fr rbossy at jouy.inra.fr
Sat Mar 8 09:18:26 EST 2008


Quoting Maryam Saeedi <saeed008 at umn.edu>:

> I have a problem using os.chdir on linux. What should I do if I want to
> change to root directory? The below does not work:
>
> 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'))

Cheers,
RB



More information about the Python-list mailing list