Re: os.chdir

Discussion in 'Python' started by rbossy@jouy.inra.fr, Mar 8, 2008.

  1. Guest

    Quoting Maryam Saeedi <>:

    > 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
     
    , Mar 8, 2008
    #1
    1. Advertising

  2. >> 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
     
    Martin v. Löwis, Mar 8, 2008
    #2
    1. Advertising

  3. Guest

    Quoting "Martin v. Löwis" <>:

    > >> 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
     
    , Mar 8, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Schull

    cgi-tb after os.chdir

    Jon Schull, Jul 14, 2003, in forum: Python
    Replies:
    0
    Views:
    410
    Jon Schull
    Jul 14, 2003
  2. Yun Mao

    os.environ and os.path.chdir

    Yun Mao, Sep 20, 2003, in forum: Python
    Replies:
    4
    Views:
    440
    Thomas Bellman
    Sep 20, 2003
  3. Tom McDavid
    Replies:
    0
    Views:
    480
    Tom McDavid
    May 13, 2004
  4. Philippe C. Martin

    os.chdir + GUI question

    Philippe C. Martin, Dec 3, 2005, in forum: Python
    Replies:
    0
    Views:
    307
    Philippe C. Martin
    Dec 3, 2005
  5. Replies:
    3
    Views:
    602
    DataSmash
    Jun 2, 2006
Loading...

Share This Page