Re: how can I implement "cd" like shell in Python?

Discussion in 'Python' started by Dave Angel, Jun 28, 2012.

  1. Dave Angel

    Dave Angel Guest

    On 06/28/2012 05:30 AM, æ¢¦å¹»è‰ wrote:
    > how can I implement "cd" like shell in Python?
    >


    import os
    os.chdir("newdirectory")


    But the more important question is why you want to. Inside a Python
    program, many people find that changing directory causes unexpected
    difficulties, and they simply keep track of a full path instead, using
    various os.path functions to manage it.

    And once the python program ends, the shell should have no knowledge of
    what you changed it to.

    Now, a particular shell program might have some convention that allows a
    program to inform it what directory to continue in. But that's a
    question about that shell, not about Python. And you never said what
    your environment is.


    So give some more specifics to your needs, and somebody is likely to
    know an approach.



    --

    DaveA
    Dave Angel, Jun 28, 2012
    #1
    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. ÃλòÝ
    Replies:
    0
    Views:
    180
    ÃλòÝ
    Jun 28, 2012
  2. Sergi Pasoev
    Replies:
    2
    Views:
    451
    Laurent Pointal
    Jun 28, 2012
  3. Kushal Kumaran
    Replies:
    0
    Views:
    193
    Kushal Kumaran
    Jun 28, 2012
  4. Evan Driscoll
    Replies:
    0
    Views:
    192
    Evan Driscoll
    Jun 28, 2012
  5. Chris Withers
    Replies:
    0
    Views:
    217
    Chris Withers
    Jun 29, 2012
Loading...

Share This Page