473,289 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

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 3041
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Glenn A. Harlan | last post by:
Why am I receiving the below error when calling - Path.GetTempFileName() The directory name is invalid. Description: An unhandled exception occurred during the execution of the current web...
1
by: jwpioneer | last post by:
I have a need within an application to modify the path environment variable, as I need to find specific directories and remove them. I use the following code to do this: RegistryKey rkey = ...
10
by: wen | last post by:
on my system(win2k server, python 2.3.5), >>> import sys >>> print sys.path now, i wanna add "C:\Python23\Pmw\Pmw_1_2\lib" into sys.path, how? any help would be appreciated. with my...
1
by: Chris B | last post by:
I have an application that uses PInvoke to call into native DLLs. My DLLimport attribute only has the name of the DLL that I need to import (i.e. I leave it up to the OS to search the PATH for the...
1
by: Bonj | last post by:
Hi My application installs a front-end GUI, which runs code when buttons are clicked. It also installs a command-line utility, that is a console application. They are both installed to the...
4
by: | last post by:
Hi all, I am trying to append a certain string to the PATH environment variable programmatically. I am able to read what is in the variable using the System.Environment method...
6
by: Garfield | last post by:
We have written a small function to append a couple of paths to the path environmental variable. The code is: string PathValue = ""; string sAdd = ""; sAdd = ";" + <path1> + "Bin;" +...
1
by: Colmag | last post by:
I remember setting the PATH environment variable from years back, but haven't touched it since win95 days. Now i have to add a couple of lines to it using vb.net so that a console app will work...
3
by: HMS Surprise | last post by:
Is sys.path setup differnently in jython vs python? I have environment variables pythonpath and jythonpath set to include C:\python22 but the initial printout indicates it is being ignored. Also...
2
by: Blair | last post by:
Hello, I have a old enviromantal path in LIB file that, every time I compile gives a error message. It does not stop the compiler just gives a warning. This has become very annoying. I...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.