[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: os.chdir

rbossy

3/8/2008 2:18:00 PM

Quoting Maryam Saeedi <saeed008@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
2 Answers

Martin v. Loewis

3/8/2008 2:35:00 PM

0

>> 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

rbossy

3/8/2008 2:50:00 PM

0

Quoting "Martin v. Löwis" <martin@v.loewis.de>:

> >> 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"))

Well... duh!
Thanks for reminding me.
Cheers,
RB