Platform-independent way to refer to execute path

M

MK

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,
 
P

Peter Hansen

MK said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top