Professional IronPython


ACCEssIng THE sTAndARd LIbRARy FRoM IRonPyTHon



Download 20,35 Mb.
Pdf ko'rish
bet124/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   120   121   122   123   124   125   126   127   ...   453
ACCEssIng THE sTAndARd LIbRARy FRoM IRonPyTHon
Before you can use the Python Standard Library to create applications, you must provide a means 
for IronPython to find the Standard Library so it can import modules. You have three options for 
performing this task.
➤➤
Create an environment variable named 
IRONPYTHONPATH
and provide the path to the 
Standard Library through it. The “Understanding the IPY.EXE Command Line Syntax” 
548592c06.indd 102
2/24/10 12:47:52 PM
www.finebook.ir


Accessing the Standard Library from IronPython
 

 
103
section of Chapter 1 tells you how to work with environment variables. This option is 
machine-specific, but it does work.


Manually add the path to the import search path (discussed later in this section). The advan-
tage of this method is that the import requirements move with the application. However, if the 
user has their copy of the Standard Library in a different location (or doesn’t have the Standard 
Library installed at all), the change can break your application.


Add the path to 
site.py
, which is located in the 
\Program Files\IronPython 2.6\Lib
directory of your machine. The interpreter loads this file every time it starts, so you can be 
sure that everyone using the IronPython interpreter on your machine will have the required 
access. As with the 
IRONPYTHONPATH
environment variable, this solution works on the cur-
rent machine only.
Manually Adding the Import search Path
In order to manually add the import search path, you need to add code to every application created. 
The code isn’t long or hard to understand, but you must add it to every application that requires the 
Standard Library or the application won’t be able to access it. Here’s an example of the code you need.
import sys
sys.path.append(‘C:\Python26\Lib’)
In this case, my copy of the Standard Library is located in 
C:\Python26\Lib
, which is the default 
setup. You need to change this value to match your system. After you make the change, you can 
verify that it’s correct by using the following code.
print sys.path[len(sys.path)-1]
All that this code does is display the last path added to 
sys.path
. If you see the appropriate path, 
you know you’re ready to go.

Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   120   121   122   123   124   125   126   127   ...   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