Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet227/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   223   224   225   226   227   228   229   230   ...   453
Using the Python method
Python provides operating system–generic methods of reading and writing variables. As with 
many things in IronPython, the Python techniques work great across platforms, but probably 
won’t provide the greatest flexibility. The following sections describe the techniques you use to 
read and set environment variables using the Python method.
Reading the Environment Variables Using Python
This example looks at a new Python module, 
os
, which contains a number of interesting classes. In 
this case, you use the 
environ
class, which provides access to the environment variables and lets you 
manipulate them in various ways, as shown in Listing 10-6.
LISTINg 10-6: 
 Displaying the environment variables using the Python method
# Import the required Python modules.
import os
# Obtain the environment variable keys.
Variables = os.environ.keys()
# Sort the keys in alphabetic order.
Variables.sort()
# Display the keys and their associated values.
for Var in Variables:
print ‘%30s %s’ % (Var,os.environ[Var])
# Pause after the debug session.
raw_input(‘\nPress any key to continue...’)
The code begins by importing the required modules, as normal. It then places the list of environment 
variable keys, the names, in 
Variables
using 
os.environ.keys()
. In most cases, you want to view 
the environment variables in sorted order because there are too many of them to simply peruse a list, 
so the code sorts the list using 
Variables.sort()
.
At this point, the code is ready to display the list. It uses a simple 
for
loop to perform the task. 
Notice the use of formatting to make the output more readable. Remember that the values don’t 
548592c10.indd 211
2/24/10 12:48:32 PM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   223   224   225   226   227   228   229   230   ...   453




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish