Platform-independent way to refer to execute path

Discussion in 'Python' started by MK, Jun 25, 2003.

  1. MK

    MK Guest

    What would be the best platform-independent way to refer
    to the current (execute) path for a Python script?

    self.dirname = ???

    This variable should contain directory name for the current path.
    It should work on every platform (Linux, Windows...). I'm
    not interested in parsing this string. That is, simple

    f.write(self.dirname)

    should work, withour ever peeking into the string. Thx,
    MK, Jun 25, 2003
    #1
    1. Advertising

  2. MK

    Peter Hansen Guest

    MK wrote:
    >
    > What would be the best platform-independent way to refer
    > to the current (execute) path for a Python script?
    >
    > self.dirname = ???
    >
    > This variable should contain directory name for the current path.


    The question seems ambiguous to me. What is the "current path"?
    There is a PATH environment variable, but you probably don't mean
    that. There is also a current directory, or "current working directory",
    which is accessible through os.getcwd(). Will that do? If so, make
    sure you read the rest of the docs on the "os" module so you'll
    know what is there for later.

    -Peter
    Peter Hansen, Jun 25, 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. Gandalf
    Replies:
    1
    Views:
    300
    Lawrence Oluyede
    Aug 18, 2004
  2. =?iso-8859-1?B?QW5kcuk=?=
    Replies:
    8
    Views:
    379
    =?iso-8859-1?B?QW5kcuk=?=
    May 1, 2007
  3. Jan Thomä
    Replies:
    15
    Views:
    2,523
    Jan Thomä
    Feb 19, 2009
  4. Daniel Fetchinson
    Replies:
    49
    Views:
    1,346
    alex23
    Aug 6, 2010
  5. PeterB
    Replies:
    1
    Views:
    132
    PeterB
    Feb 10, 2005
Loading...

Share This Page