Re: sys.path[0] in IDLE

Discussion in 'Python' started by Gabriel Genellina, Dec 27, 2003.

  1. At 26/12/2003 22:25, you wrote:

    >Am I reading this correctly?
    >
    >http://python.org/doc/current/lib/module-sys.html
    >
    >"""
    >As initialized upon program startup, the first item of this list,
    >path[0], is the directory containing the script that was used to
    >invoke the Python interpreter.
    >"""
    >
    >
    >So, sys.path[0] should be the directory that my script is in?
    >
    >Even if running the script from IDLE?
    >
    >Has anyone else had problems with this? Especially on windows?


    (Read the remaining of the paragraph too)
    When using IDLE, the "script" is really idle.py. If you start IDLE with
    another script as an argument, its dir is prepended in sys.path


    Gabriel Genellina
    Softlab SRL
     
    Gabriel Genellina, Dec 27, 2003
    #1
    1. Advertising

  2. Gabriel Genellina

    Lee Harr Guest

    On 2003-12-27, Gabriel Genellina <> wrote:
    > At 26/12/2003 22:25, you wrote:
    >
    >>Am I reading this correctly?
    >>
    >>http://python.org/doc/current/lib/module-sys.html
    >>
    >>"""
    >>As initialized upon program startup, the first item of this list,
    >>path[0], is the directory containing the script that was used to
    >>invoke the Python interpreter.
    >>"""
    >>
    >>
    >>So, sys.path[0] should be the directory that my script is in?
    >>
    >>Even if running the script from IDLE?
    >>
    >>Has anyone else had problems with this? Especially on windows?

    >
    > (Read the remaining of the paragraph too)
    > When using IDLE, the "script" is really idle.py. If you start IDLE with
    > another script as an argument, its dir is prepended in sys.path
    >
    >



    So, are you saying you do not see your script as sys.path[0] also?

    That seems like a bug to me.

    It works fine for me on FreeBSD 4.9 with python 2.3, so it can't be
    that IDLE needs to have its own directories in the path before mine.

    What do others get saving this script in IDLE and running it?



    # /usr/home/lee/python/idle_test/foo/bar.py
    import sys
    print sys.path





    IDLE 1.0.2
    >>> import sys
    >>> print sys.path

    ['/usr/home/lee', '/usr/local/bin', '/usr/local/lib/python23.zip', ...]
    >>> # now open /usr/home/lee/python/idle_test/foo/bar.py and run the script
    >>> ================================ RESTART ================================
    >>>

    ['/usr/home/lee/python/idle_test/foo', '/usr/home/lee', '/usr/local/bin', ...]
    >>>
     
    Lee Harr, Dec 28, 2003
    #2
    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. Ronald Meier
    Replies:
    2
    Views:
    1,516
    Keith S.
    Oct 21, 2003
  2. Jeff Wagner

    sys.path.append('/my/new/path')

    Jeff Wagner, Nov 24, 2003, in forum: Python
    Replies:
    3
    Views:
    537
    Patrick Useldinger
    Nov 24, 2003
  3. Lee Harr

    sys.path[0] in IDLE

    Lee Harr, Dec 26, 2003, in forum: Python
    Replies:
    0
    Views:
    342
    Lee Harr
    Dec 26, 2003
  4. Replies:
    3
    Views:
    407
  5. wen
    Replies:
    10
    Views:
    989
    Peter Hansen
    Aug 19, 2005
Loading...

Share This Page