Mark Kels wrote:

Hello to all :-)

I'm writing a CGI script (one of my first ever CGI programs and I'm
using this tutor to learn CGI: http://www.oreilly.com/openbook/cgi/
This isn't a python tutor, but the introductions says that any
language will be good for this tutor.
Anyway, I got to the Using Environment Variables chapter that is in
this page: http://www.oreilly.com/openbook/cgi/ch02_02.html.
This is UNIX environment variables (as I understand), and I guess they
will not work on Windows...
So what are the Windows environment variables and how can I use them
with python (like any other variable or in a special way?) ?

Thanks!


Morning Mark,

Happy New Year, Merry Christmas, and a jolly Winter Solstice Season!

Whenever you're talking about how to do something in Windows it REALLY helps when you include WHICH windows you're working with.

I believe the following will allow you to manipulate windows environmental variables. If anyone sees I'm wrong I know they'll speak up. The "set" command when run in a command window without parameters lists your current environmental variables. You can also use it as:
c:\> set hello=Hi there Mark
which will set the variable "HELLO" to "Hi there Mark".
c:\> echo %HELLO% or
c:\> echo %hello%
will now print "Hi there Mark" without the quotes.


Note that quoting, case sensitivity, and white spaces can all react differently under windows than they do in Python.

If you need to set an environmental variable to a value every time you start windows then you can either store the above set command (no spaces around that "=" remember) in the autoexec.bat file or on Windows 2000, XP and (I believe) NT you can right click on the desktop icon "My Computer" and select "Properties". Now you're looking for the "Advanced" tab and the environmental variables button in Windows 2000. I THINK it's under the "System Performance" tab and advanced button in XP and you'll have to dig in NT. I'm not sure you can do this here under the win 95/98/ME family. Sorry, right now the only windows product I'm running at home is 2000.

You can also set Windows environmental variables from within your python script of course.

FYI being a coward myself before I go changing my setup I like to document things. Say running "set > Environment-Before.txt" in a nice safe directory. This will output your current setup so if things get weird you can at least bring things back to you starting point.

Have a good one,

John Purser
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to