Changing the current directory (full post)

Discussion in 'Python' started by vsoler, Nov 15, 2009.

  1. vsoler

    vsoler Guest

    Oops!!! something went wrong with my keyboard. Here you have my full
    post:

    Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
    been saving my
    *.py files in the C:\Program Files\Python26 directory, which is the
    default directory for such files in my system.

    However, I have realised that the above is not the best practice.
    Therefore I created the C:\Program Files\Python26\test directory and I
    want it to be my default directory for saving *.py files, importing
    modules, etc.

    I'd like to do something like the DOS equivalent of "CD test" but I
    do not know kow to do it.

    I am currently doing something really awful: I open a *.py file in the
    test subdirectory, I run it with the F5 key and it works! but I am
    doing really something stupid.

    I can see that it works because if I do

    import sys
    sys.path

    .... the first directory in the list is the test one.

    How should I proceed, if I want to proceed properly?

    Vicente Soler
    vsoler, Nov 15, 2009
    #1
    1. Advertising

  2. En Sun, 15 Nov 2009 09:04:06 -0300, vsoler <>
    escribió:

    > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
    > been saving my
    > *.py files in the C:\Program Files\Python26 directory, which is the
    > default directory for such files in my system.
    >
    > However, I have realised that the above is not the best practice.
    > Therefore I created the C:\Program Files\Python26\test directory and I
    > want it to be my default directory for saving *.py files, importing
    > modules, etc.


    This is *not* a good place either. Non-privileged users should not have
    write permission in the C:\Program Files directory.

    > I'd like to do something like the DOS equivalent of "CD test" but I
    > do not know kow to do it.
    >
    > I am currently doing something really awful: I open a *.py file in the
    > test subdirectory, I run it with the F5 key and it works! but I am
    > doing really something stupid.


    "it works!" What's the problem then?

    > How should I proceed, if I want to proceed properly?


    Sorry but I don't even see your problem. You can save your .py files
    anywhere you like...

    --
    Gabriel Genellina
    Gabriel Genellina, Nov 16, 2009
    #2
    1. Advertising

  3. vsoler

    vsoler Guest

    On Nov 16, 2:35 am, "Gabriel Genellina" <>
    wrote:
    > En Sun, 15 Nov 2009 09:04:06 -0300, vsoler <>
    > escribió:
    >
    > > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
    > > been saving my
    > > *.py files in the C:\Program Files\Python26 directory, which is the
    > > default directory for such files in my system.

    >
    > > However, I have realised that the above is not the best practice.
    > > Therefore I created the C:\Program Files\Python26\test directory and I
    > > want it to be my default directory for saving *.py files, importing
    > > modules, etc.

    >
    > This is *not* a good place either. Non-privileged users should not have
    > write permission in the C:\Program Files directory.
    >
    > > I'd like to do something like the DOS equivalent of   "CD test" but I
    > > do not know kow to do it.

    >
    > > I am currently doing something really awful: I open a *.py file in the
    > > test subdirectory, I run it with the F5 key and it works! but I am
    > > doing really something stupid.

    >
    > "it works!" What's the problem then?
    >
    > > How should I proceed, if I want to proceed properly?

    >
    > Sorry but I don't even see your problem. You can save your .py files  
    > anywhere you like...
    >
    > --
    > Gabriel Genellina


    Gabriel,

    When I enter IDLE, I'd like to say at the prompt: "my current
    directory is... ...test" and then be able to run a module in that
    directory. This is what my problem is!!!

    Thank you if you can help
    vsoler, Nov 16, 2009
    #3
  4. vsoler

    Chris Rebert Guest

    On Mon, Nov 16, 2009 at 11:36 AM, vsoler <> wrote:
    > On Nov 16, 2:35 am, "Gabriel Genellina" <>
    > wrote:
    >> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler <>
    >> escribió:
    >>
    >> > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
    >> > been saving my
    >> > *.py files in the C:\Program Files\Python26 directory, which is the
    >> > default directory for such files in my system.

    >>
    >> > However, I have realised that the above is not the best practice.
    >> > Therefore I created the C:\Program Files\Python26\test directory and I
    >> > want it to be my default directory for saving *.py files, importing
    >> > modules, etc.

    >>
    >> This is *not* a good place either. Non-privileged users should not have
    >> write permission in the C:\Program Files directory.
    >>
    >> > I'd like to do something like the DOS equivalent of   "CD test" but I
    >> > do not know kow to do it.

    >>
    >> > I am currently doing something really awful: I open a *.py file in the
    >> > test subdirectory, I run it with the F5 key and it works! but I am
    >> > doing really something stupid.

    >>
    >> "it works!" What's the problem then?
    >>
    >> > How should I proceed, if I want to proceed properly?

    >>
    >> Sorry but I don't even see your problem. You can save your .py files
    >> anywhere you like...
    >>
    >> --
    >> Gabriel Genellina

    >
    > Gabriel,
    >
    > When I enter IDLE, I'd like to say at the prompt: "my current
    > directory is...  ...test" and then be able to run a module in that
    > directory. This is what my problem is!!!


    1. File -> Open
    2. Navigate to file and choose it
    3. Press F5

    Cheers,
    Chris
    --
    http://blog.rebertia.com
    Chris Rebert, Nov 16, 2009
    #4
  5. vsoler

    vsoler Guest

    On Nov 16, 8:45 pm, Chris Rebert <> wrote:
    > On Mon, Nov 16, 2009 at 11:36 AM, vsoler <> wrote:
    > > On Nov 16, 2:35 am, "Gabriel Genellina" <>
    > > wrote:
    > >> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler <>
    > >> escribió:

    >
    > >> > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
    > >> > been saving my
    > >> > *.py files in the C:\Program Files\Python26 directory, which is the
    > >> > default directory for such files in my system.

    >
    > >> > However, I have realised that the above is not the best practice.
    > >> > Therefore I created the C:\Program Files\Python26\test directory and I
    > >> > want it to be my default directory for saving *.py files, importing
    > >> > modules, etc.

    >
    > >> This is *not* a good place either. Non-privileged users should not have
    > >> write permission in the C:\Program Files directory.

    >
    > >> > I'd like to do something like the DOS equivalent of   "CD test" but I
    > >> > do not know kow to do it.

    >
    > >> > I am currently doing something really awful: I open a *.py file in the
    > >> > test subdirectory, I run it with the F5 key and it works! but I am
    > >> > doing really something stupid.

    >
    > >> "it works!" What's the problem then?

    >
    > >> > How should I proceed, if I want to proceed properly?

    >
    > >> Sorry but I don't even see your problem. You can save your .py files
    > >> anywhere you like...

    >
    > >> --
    > >> Gabriel Genellina

    >
    > > Gabriel,

    >
    > > When I enter IDLE, I'd like to say at the prompt: "my current
    > > directory is...  ...test" and then be able to run a module in that
    > > directory. This is what my problem is!!!

    >
    > 1. File -> Open
    > 2. Navigate to file and choose it
    > 3. Press F5
    >
    > Cheers,
    > Chris
    > --http://blog.rebertia.com


    Say that you wanted to import a file in the test directory after just
    entering IDLE. How would you do it?
    vsoler, Nov 16, 2009
    #5
  6. On Mon, 16 Nov 2009 11:56:49 -0800, vsoler <> wrote:

    > On Nov 16, 8:45 pm, Chris Rebert <> wrote:
    >> On Mon, Nov 16, 2009 at 11:36 AM, vsoler <>
    >> wrote:
    >> > On Nov 16, 2:35 am, "Gabriel Genellina" <>
    >> > wrote:
    >> >> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler <>
    >> >> escribió:

    >>
    >> >> > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
    >> >> > been saving my
    >> >> > *.py files in the C:\Program Files\Python26 directory, which is the
    >> >> > default directory for such files in my system.

    >>
    >> >> > However, I have realised that the above is not the best practice.
    >> >> > Therefore I created the C:\Program Files\Python26\test directory

    >> and I
    >> >> > want it to be my default directory for saving *.py files, importing
    >> >> > modules, etc.

    >>
    >> >> This is *not* a good place either. Non-privileged users should not

    >> have
    >> >> write permission in the C:\Program Files directory.

    >>
    >> >> > I'd like to do something like the DOS equivalent of   "CD test"

    >> but I
    >> >> > do not know kow to do it.

    >>
    >> >> > I am currently doing something really awful: I open a *.py file in

    >> the
    >> >> > test subdirectory, I run it with the F5 key and it works! but I am
    >> >> > doing really something stupid.

    >>
    >> >> "it works!" What's the problem then?

    >>
    >> >> > How should I proceed, if I want to proceed properly?

    >>
    >> >> Sorry but I don't even see your problem. You can save your .py files
    >> >> anywhere you like...

    >>
    >> >> --
    >> >> Gabriel Genellina

    >>
    >> > Gabriel,

    >>
    >> > When I enter IDLE, I'd like to say at the prompt: "my current
    >> > directory is...  ...test" and then be able to run a module in that
    >> > directory. This is what my problem is!!!

    >>
    >> 1. File -> Open
    >> 2. Navigate to file and choose it
    >> 3. Press F5
    >>
    >> Cheers,
    >> Chris
    >> --http://blog.rebertia.com

    >
    > Say that you wanted to import a file in the test directory after just
    > entering IDLE. How would you do it?


    http://docs.python.org/library/os.html#os.chdir and
    http://docs.python.org/library/sys.html#sys.path may be able to help you...



    --
    Rami Chowdhury
    "Never attribute to malice that which can be attributed to stupidity" --
    Hanlon's Razor
    408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
    Rami Chowdhury, Nov 16, 2009
    #6
  7. vsoler

    Chris Rebert Guest

    On Mon, Nov 16, 2009 at 11:56 AM, vsoler <> wrote:
    > On Nov 16, 8:45 pm, Chris Rebert <> wrote:
    >> On Mon, Nov 16, 2009 at 11:36 AM, vsoler <> wrote:
    >> > On Nov 16, 2:35 am, "Gabriel Genellina" <>
    >> > wrote:
    >> >> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler <>
    >> >> escribió:

    >>
    >> >> > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
    >> >> > been saving my
    >> >> > *.py files in the C:\Program Files\Python26 directory, which is the
    >> >> > default directory for such files in my system.

    >>
    >> >> > However, I have realised that the above is not the best practice.
    >> >> > Therefore I created the C:\Program Files\Python26\test directory and I
    >> >> > want it to be my default directory for saving *.py files, importing
    >> >> > modules, etc.

    >>
    >> >> This is *not* a good place either. Non-privileged users should not have
    >> >> write permission in the C:\Program Files directory.

    >>
    >> >> > I'd like to do something like the DOS equivalent of   "CD test" but I
    >> >> > do not know kow to do it.

    >>
    >> >> > I am currently doing something really awful: I open a *.py file in the
    >> >> > test subdirectory, I run it with the F5 key and it works! but I am
    >> >> > doing really something stupid.

    >>
    >> >> "it works!" What's the problem then?

    >>
    >> >> > How should I proceed, if I want to proceed properly?

    >>
    >> >> Sorry but I don't even see your problem. You can save your .py files
    >> >> anywhere you like...

    >>
    >> > When I enter IDLE, I'd like to say at the prompt: "my current
    >> > directory is...  ...test" and then be able to run a module in that
    >> > directory. This is what my problem is!!!

    >>
    >> 1. File -> Open
    >> 2. Navigate to file and choose it
    >> 3. Press F5

    >
    > Say that you wanted to import a file in the test directory after just
    > entering IDLE. How would you do it?


    import sys
    sys.path.insert(0, "C:/path/to/test/dir/here")
    import something_in_test_dir

    Cheers,
    Chris
    --
    http://blog.rebertia.com
    Chris Rebert, Nov 16, 2009
    #7
  8. vsoler

    Dave Angel Guest

    Chris Rebert wrote:
    > On Mon, Nov 16, 2009 at 11:56 AM, vsoler <> wrote:
    >
    >> On Nov 16, 8:45 pm, Chris Rebert <> wrote:
    >>
    >>> On Mon, Nov 16, 2009 at 11:36 AM, vsoler <> wrote:
    >>>
    >>>> On Nov 16, 2:35 am, "Gabriel Genellina" <>
    >>>> wrote:
    >>>>
    >>>>> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler <>
    >>>>> escribió:
    >>>>>
    >>>>>> Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
    >>>>>> been saving my
    >>>>>> *.py files in the C:\Program Files\Python26 directory, which is the
    >>>>>> default directory for such files in my system.
    >>>>>>
    >>>>>> However, I have realised that the above is not the best practice.
    >>>>>> Therefore I created the C:\Program Files\Python26\test directory and I
    >>>>>> want it to be my default directory for saving *.py files, importing
    >>>>>> modules, etc.
    >>>>>>
    >>>>> This is *not* a good place either. Non-privileged users should not have
    >>>>> write permission in the C:\Program Files directory.
    >>>>>
    >>>>>> I'd like to do something like the DOS equivalent of "CD test" but I
    >>>>>> do not know kow to do it.
    >>>>>>
    >>>>>> I am currently doing something really awful: I open a *.py file in the
    >>>>>> test subdirectory, I run it with the F5 key and it works! but I am
    >>>>>> doing really something stupid.
    >>>>>>
    >>>>> "it works!" What's the problem then?
    >>>>>
    >>>>>> How should I proceed, if I want to proceed properly?
    >>>>>>
    >>>>> Sorry but I don't even see your problem. You can save your .py files
    >>>>> anywhere you like...
    >>>>>
    >>>> When I enter IDLE, I'd like to say at the prompt: "my current
    >>>> directory is... ...test" and then be able to run a module in that
    >>>> directory. This is what my problem is!!!
    >>>>
    >>> 1. File -> Open
    >>> 2. Navigate to file and choose it
    >>> 3. Press F5
    >>>

    >> Say that you wanted to import a file in the test directory after just
    >> entering IDLE. How would you do it?
    >>

    >
    > import sys
    > sys.path.insert(0, "C:/path/to/test/dir/here")
    > import something_in_test_dir
    >
    > Cheers,
    > Chris
    > --
    > http://blog.rebertia.com
    >
    >

    Change directory to the test-directory
    Then run idle
    Dave Angel, Nov 16, 2009
    #8
  9. En Mon, 16 Nov 2009 18:10:51 -0300, Dave Angel <> escribió:
    > Chris Rebert wrote:
    >> On Mon, Nov 16, 2009 at 11:56 AM, vsoler <>
    >> wrote:


    >>>>> When I enter IDLE, I'd like to say at the prompt: "my current
    >>>>> directory is... ...test" and then be able to run a module in that
    >>>>> directory. This is what my problem is!!!


    > Change directory to the test-directory
    > Then run idle


    Or, modify the Initial Directory in the menu shortcut that you use to
    start IDLE (right click, Properties). Or create another shortcut in your
    desktop using your desired initial directory.

    --
    Gabriel Genellina
    Gabriel Genellina, Nov 16, 2009
    #9
    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. PHaroZ
    Replies:
    5
    Views:
    94,678
    akash02sap
    Aug 17, 2012
  2. Andy B.
    Replies:
    4
    Views:
    24,313
    firebush
    Jan 30, 2011
  3. Peter Hansen
    Replies:
    1
    Views:
    318
    Mike Meyer
    Dec 19, 2005
  4. Dave Rudolf
    Replies:
    2
    Views:
    365
    Daniel Pitts
    Jan 17, 2007
  5. Replies:
    26
    Views:
    1,002
    Lew Pitcher
    Jun 4, 2007
Loading...

Share This Page