[Tutor] Noob to Python - Need help with Variables
Gerrit Holl
gerrit@nl.linux.org
Thu Jun 5 09:04:25 2003
Tony Stevenson schreef op donderdag 5 juni om 13:12:40 +0000:
> I am completely new to programming, so I thought I would start with Python
> as it comes highly reccomended, and have seen it do some very smart
> things.
Congratulation on finding Python!
> >>> user = "print os.environ['USERNAME']"
You are now creating a string called 'user', with the
contents you assign to it. But it is not what you want:
you want to assign the contents of os.environ['USERNAME']
to the variable 'user'. To do this, you do:
>>> user = os.environ['USERNAME']
Strings are not (normally) executed in Python: only when passed
to the eval function. Whe you do eval(user) in your application,
you should get the username.
yours,
Gerrit.
--
281. If they are from another country, the buyer shall declare the
amount of money paid therefor to the merchant, and keep the male or female
slave.
-- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
http://www.sp.nl/