Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > PATH environment variable

Reply
Thread Tools

PATH environment variable

 
 
mirandacascade@yahoo.com
Guest
Posts: n/a
 
      11-20-2005
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?

 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      11-20-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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>



 
Reply With Quote
 
 
 
 
Jeffrey Schwab
Guest
Posts: n/a
 
      11-20-2005
(E-Mail Removed) 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')
 
Reply With Quote
 
mirandacascade@yahoo.com
Guest
Posts: n/a
 
      11-20-2005
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?

 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      11-20-2005
(E-Mail Removed) 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>



 
Reply With Quote
 
mirandacascade@yahoo.com
Guest
Posts: n/a
 
      11-20-2005
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?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how set the PATH environment variable to server machine through myapplication? chandan ASP .Net Web Services 1 01-08-2008 04:13 PM
How can I set the PATH environment variable to server machine inasp.net ? chandan ASP .Net 1 01-08-2008 07:52 AM
Setting an environment variable from another environment variable marcwentink@hotmail.com Java 5 04-04-2007 10:39 PM
ASP.Net and PATH environment variable Chris Ashley ASP .Net 0 11-07-2006 09:16 AM
environment variable as part of a src path Glennn HTML 5 04-06-2006 04:54 PM



Advertisments