Professional IronPython


Importing the .NET Framework Assemblies



Download 20,35 Mb.
Pdf ko'rish
bet138/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   134   135   136   137   138   139   140   141   ...   453
Importing the .NET Framework Assemblies
 

 
121
The asterisk (*) means that you import everything in the 
System
assembly at the global 
namespace level. Figure 7-4 shows what happens when you use the 
dir()
function to see the 
global namespace.
FIguRE 7-4: 
You can import an entire assembly into the global namespace.
If you want a specific class within the 
System
assembly imported at the global namespace level, you 
simply specify the name of the class as you would when working with Python. For example, if you 
want to work with the 
Console
class, then you’d type
from System import Console
548592c07.indd 121
2/25/10 9:44:26 AM
www.finebook.ir


122

CHAPTER 7
Accessing the .net FrAmework
Some developers will be tempted to import everything they need into the global 
namespace. While this strategy works fine for a .NET application created in a 
language such as C#, it doesn’t always work well in IronPython because of the 
way the Python language works. For example, Figure 7-4 shows an example of 
the problems that can occur. Imagine importing four or five assemblies into the 
global namespace and then using the 
dir()
 function to display a list of classes, 
methods, enumerations, or other .NET features you want to use. The list would 
be so large as to make any search pointless. Import only what you need into the 
global namespace.
You can extend individual imports by separating classes, enumerations, or other assembly members 
with commas. For example, if you want to import both the 
Console
class and the 
ConsoleColor
enumeration into the global namespace, you type
from System import Console, ConsoleColor
If you use the 
dir()
function to see the result, you see output similar to Figure 7-5. Importing only 
what you need keeps clutter down, makes your application run faster, and reduces potential security 
issues. In this case, you can reduce the foreground color-changing code shown in the “Performing a 
Standard Import” section to
Console.ForegroundColor = ConsoleColor.Blue

Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   134   135   136   137   138   139   140   141   ...   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