Platform-independent way to refer to execute path

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MK

    Platform-independent way to refer to execute path

    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.di rname)

    should work, withour ever peeking into the string. Thx,


  • Peter Hansen

    #2
    Re: Platform-independent way to refer to execute path

    MK wrote:[color=blue]
    >
    > 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.[/color]

    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

    Comment

    Working...