469,280 Members | 1,813 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,280 developers. It's quick & easy.

PATH environment variable

O/S: Win2K
Vsn of Python:2.4

Based on a search of other posts in this group, it appears as though
os.environ['PATH'] is one way to obtain the PATH environment variable.

My questions:
1) is it correct that os.environ['PATH'] contains the PATH environment
variable?
2) are there other ways to obtain the PATH environment variable? if so,
is one way of obtaining the PATH environment variable preferable to
another way?

Nov 22 '05 #1
10 2879
mi************@yahoo.com wrote:
Based on a search of other posts in this group, it appears as though
os.environ['PATH'] is one way to obtain the PATH environment variable.

My questions:
1) is it correct that os.environ['PATH'] contains the PATH environment
variable?
yes.
2) are there other ways to obtain the PATH environment variable? if so,
is one way of obtaining the PATH environment variable preferable to
another way?


no. using the environ variable is the preferred way to read environment
variables.

</F>

Nov 22 '05 #2
mi************@yahoo.com wrote:
Based on a search of other posts in this group, it appears as though
os.environ['PATH'] is one way to obtain the PATH environment variable.

My questions:
1) is it correct that os.environ['PATH'] contains the PATH environment
variable?
yes.
2) are there other ways to obtain the PATH environment variable? if so,
is one way of obtaining the PATH environment variable preferable to
another way?


no. using the environ variable is the preferred way to read environment
variables.

</F>

Nov 22 '05 #3
mi************@yahoo.com wrote:
O/S: Win2K
Vsn of Python:2.4

Based on a search of other posts in this group, it appears as though
os.environ['PATH'] is one way to obtain the PATH environment variable.

My questions:
1) is it correct that os.environ['PATH'] contains the PATH environment
variable?
2) are there other ways to obtain the PATH environment variable? if so,
is one way of obtaining the PATH environment variable preferable to
another way?


That's the best way because it's portable. If you didn't have
os.environ, you might be able to get PATH but reading the output of some
subprocess, e.g:

import commands
path = commands.getoutput('echo $PATH')
Nov 22 '05 #4
mi************@yahoo.com wrote:
O/S: Win2K
Vsn of Python:2.4

Based on a search of other posts in this group, it appears as though
os.environ['PATH'] is one way to obtain the PATH environment variable.

My questions:
1) is it correct that os.environ['PATH'] contains the PATH environment
variable?
2) are there other ways to obtain the PATH environment variable? if so,
is one way of obtaining the PATH environment variable preferable to
another way?


That's the best way because it's portable. If you didn't have
os.environ, you might be able to get PATH but reading the output of some
subprocess, e.g:

import commands
path = commands.getoutput('echo $PATH')
Nov 22 '05 #5
I observed something tangential to this topic, and that is the reason
for this reply. I don't understand when os.environ gets updated. The
'...captured the first time the os mdule is imported...' verbiage from
the following link:

http://www.python.org/dev/doc/newsty...-procinfo.html

provides some information, but it's not clear how to make that fit with
the following observations:

Sequence of steps...observation 1:
1) open Pythonwin interactive window
2) import os
3) os.environ['PATH'] - this presents the contents of the PATH variable
4) using Windows system properties/environment variables, change
contents of PATH variable; apply the changes (after closing, I got back
in to verify that the PATH variable was, in fact, changed)
5) in interactive window, reload(os)
6) os.environ['PATH'] - presents same value is in #3

Sequence of steps...observation 2:
1) open Pythonwin interactive window
2) import os
3) os.environ['PATH'] - this presents the contents of the PATH variable
4) using Windows system properties/environment variables, change
contents of PATH variable; apply the changes (after closing, I got back
in to verify that the PATH variable was, in fact, changed)
5) in interactive window, del os
6) in interactive window, import os
7) os.environ['PATH'] - presents the same value as in #3

I also observed that if I exit the interactive window, and then go back
into the interactive window, the os.environ['PATH'] reflects changes to
the PATH environment variable that happened while in the interactive
window the first time.

Do these observations fit with what is stated in section 6.1.1 of the
Python Library Reference?

Nov 22 '05 #6
I observed something tangential to this topic, and that is the reason
for this reply. I don't understand when os.environ gets updated. The
'...captured the first time the os mdule is imported...' verbiage from
the following link:

http://www.python.org/dev/doc/newsty...-procinfo.html

provides some information, but it's not clear how to make that fit with
the following observations:

Sequence of steps...observation 1:
1) open Pythonwin interactive window
2) import os
3) os.environ['PATH'] - this presents the contents of the PATH variable
4) using Windows system properties/environment variables, change
contents of PATH variable; apply the changes (after closing, I got back
in to verify that the PATH variable was, in fact, changed)
5) in interactive window, reload(os)
6) os.environ['PATH'] - presents same value is in #3

Sequence of steps...observation 2:
1) open Pythonwin interactive window
2) import os
3) os.environ['PATH'] - this presents the contents of the PATH variable
4) using Windows system properties/environment variables, change
contents of PATH variable; apply the changes (after closing, I got back
in to verify that the PATH variable was, in fact, changed)
5) in interactive window, del os
6) in interactive window, import os
7) os.environ['PATH'] - presents the same value as in #3

I also observed that if I exit the interactive window, and then go back
into the interactive window, the os.environ['PATH'] reflects changes to
the PATH environment variable that happened while in the interactive
window the first time.

Do these observations fit with what is stated in section 6.1.1 of the
Python Library Reference?

Nov 22 '05 #7
mi************@yahoo.com wrote:
Do these observations fit with what is stated in section 6.1.1 of the
Python Library Reference?


yes. what part of your observations makes you think that the
environment isn't "captured" (i.e. copied from the process environ-
ment) when the os module is imported ?

(hint: when you start a new process, it gets a *copy* of the
current environment. changes to the original won't affect this
copy. all modern operating systems work the same way).

</F>

Nov 22 '05 #8
mi************@yahoo.com wrote:
Do these observations fit with what is stated in section 6.1.1 of the
Python Library Reference?


yes. what part of your observations makes you think that the
environment isn't "captured" (i.e. copied from the process environ-
ment) when the os module is imported ?

(hint: when you start a new process, it gets a *copy* of the
current environment. changes to the original won't affect this
copy. all modern operating systems work the same way).

</F>

Nov 22 '05 #9
Fredrik Lundh wrote:
what part of your observations makes you think that the environment isn't "captured" (i.e. > copied from the process environment) when the os module is imported ?


Answer: the part that was informed by a fundamental misunderstanding on
my part of how the os module obtains information.

Based on Mr. Lundh's 'copied from the process environment' remark and
his hint, I would infer the following:

1) In the observations I detailed, the 'process' is the pythonwin
application
2) When the pythonwin application is invoked, it obtains a copy of the
current environment
3) the import os statement obtains information from the copy of the
current environment that was obtained when the pythonwin process began
4) a reload(os) or a combination of del os followed by import os also
get information from the copy of the current environment that was
obtained when the pythonwin process began

My questions:
a) are the above inferences (albeit oversimplified) correct?
b) when the hint refers to a new process, does the term 'process' refer
to the same concept that is described in secion 6.1.5 of the Python
Library Reference?

Nov 22 '05 #10
Fredrik Lundh wrote:
what part of your observations makes you think that the environment isn't "captured" (i.e. > copied from the process environment) when the os module is imported ?


Answer: the part that was informed by a fundamental misunderstanding on
my part of how the os module obtains information.

Based on Mr. Lundh's 'copied from the process environment' remark and
his hint, I would infer the following:

1) In the observations I detailed, the 'process' is the pythonwin
application
2) When the pythonwin application is invoked, it obtains a copy of the
current environment
3) the import os statement obtains information from the copy of the
current environment that was obtained when the pythonwin process began
4) a reload(os) or a combination of del os followed by import os also
get information from the copy of the current environment that was
obtained when the pythonwin process began

My questions:
a) are the above inferences (albeit oversimplified) correct?
b) when the hint refers to a new process, does the term 'process' refer
to the same concept that is described in secion 6.1.5 of the Python
Library Reference?

Nov 22 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by jwpioneer | last post: by
10 posts views Thread by wen | last post: by
1 post views Thread by Chris B | last post: by
1 post views Thread by Bonj | last post: by
4 posts views Thread by | last post: by
1 post views Thread by Colmag | last post: by
3 posts views Thread by HMS Surprise | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.