Getting original working directory

Ben Finney bignose+hates-spam at benfinney.id.au
Thu Sep 6 20:00:50 EDT 2007


Please don't top-post. Instead, trim the parts you're not replying to
(preserving the attribution line so we can see who wrote what), and
put your reply beneath those, so your message reads in normal
chronological order.

rave247 rave247 <rave247 at seznam.cz> writes:

> If I could use os.getcwd() or save the value to some variable before
> calling os.chdir() I would do it, believe me. However I can't
> because it is the part of code where I can't do any changes.

Then why not get the value from 'os.getcwd()' *before* calling the
"part of code where you can't make changes"? You're the one writing
the program, you can decide which actions happen in which order.

> So this information has to be stored somewhere (probably in shell
> which runs the interpreter)

In the parent process of the Python program, yes.

> and there *must* be a way how to get it.

This doesn't follow at all. Child processes get only a small,
well-specified set of values from their parent (via the operating
system), and are deliberately restricted from poking around inside
their parent. Think for a while on how you'd have to write such a
parent process to account for such meddling and you'll appreciate why.

> Simply after calling os.chdir() the original value doen't disappear

For the current running process, it does. Just as in Python binding a
different value to a name means the previous value is lost — unless
you bind that previous value somewhere else first so you can get at it
again.

-- 
 \         "I got up the other day, and everything in my apartment has |
  `\       been stolen and replaced with an exact replica."  -- Steven |
_o__)                                                           Wright |
Ben Finney



More information about the Python-list mailing list