473,626 Members | 3,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3063
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.getout put('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.getout put('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...observa tion 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...observa tion 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...observa tion 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...observa tion 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 misunderstandin g 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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
17469
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 request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.IOException: The directory name is invalid.
1
2239
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 = null; rkey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment",true); string p = (String)rkey.GetValue("Path"); string pp = p.Split(';');
10
12828
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 kind regards,
1
9696
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 DLL.) This all works great when the user's PATH variable is setup correctly. Unfortunately, there are times when the user's PATH is too full or whatever to have the correct search path for my application. What I was wondering is if there is...
1
2452
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 program's application directory, along with the DLL that contains the generic code that they both call. My question is, is there any way of modifying the environment variable permanently with the setup project, such that the user has got the...
4
39080
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 GetEnvironmentVariable("path"). However, I don't know yet how to append strings to the path variable. Any help is appreciated. Thanks a lot.
6
6410
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;" + <path2>; PathValue = System.Environment.GetEnvironmentVariable("Path"); PathValue += sAdd;
1
5810
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 properly. I've read that at the moment you can only get environment variables, and that vb.net 2005 will allow you to set them. Does anyone know how to add to the PATH variable using vb.net 2003?
3
3895
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 when I used sys.path.extend, the added pathname shows up as a series of single characters. Have I misused .extend? Thanks, jh
2
1435
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 would like to delete out of the listing as I don't use the LIB anymore, but I am lost as how to do it.
0
8269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8203
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8642
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2630
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1515
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.