Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #27298

How to get initial absolute working dir reliably?

From kj <no.email@please.post>
Newsgroups comp.lang.python
Subject How to get initial absolute working dir reliably?
Date 2012-08-18 15:19 +0000
Organization none
Message-ID <k0obqv$hgg$1@reader1.panix.com> (permalink)

Show all headers | View raw



What's the most reliable way for "module code" to determine the
absolute path of the working directory at the start of execution?

(By "module code" I mean code that lives in a file that is not
meant to be run as a script, but rather it is meant to be loaded
as the result of some import statement.  In other words, "module
code" is code that must operate under the assumption that it can
be loaded at any time after the start of execution.)

Functions like os.path.abspath produce wrong results if the working
directory is changed, e.g. through os.chdir, so it is not terribly
reliable for determining the initial working directory.

Basically, I'm looking for a read-only variable (or variables)
initialized by Python at the start of execution, and from which
the initial working directory may be read or computed.


Thanks!

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

How to get initial absolute working dir reliably? kj <no.email@please.post> - 2012-08-18 15:19 +0000
  Re: How to get initial absolute working dir reliably? alex23 <wuwei23@gmail.com> - 2012-08-19 16:58 -0700

csiph-web