By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,652 Members | 1,697 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,652 IT Pros & Developers. It's quick & easy.

Platform-independent way to refer to execute path

P: n/a
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,
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.