Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet147/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   143   144   145   146   147   148   149   150   ...   453
130

CHAPTER 7
Accessing the .net FrAmework
FIguRE 7-11: 
IronPython doesn’t limit the information you receive about assemblies.
Working with the attributes can prove a little tricky because they each contain different values. 
When working with the 
AssemblyCompanyAttribute
, for example, you can access the 
Company
property that contains the name of the company that created the attribute. Of course, nothing dif-
fers from any other .NET language in this case. You need to know precisely which attributes you 
want to query and the properties within those attributes that contain the values you need in order to 
interact with attributes successfully.
making Static method Calls
Many of the tasks you perform using .NET require use of static methods. Static methods
work the same in IronPython as they do in any .NET language. Listing 7-2 shows some static 
method calls that work with the current date and time. The techniques shown work with any 
static method.
548592c07.indd 130
2/25/10 9:44:29 AM
www.finebook.ir


Interacting with .NET Framework Elements
 

 
131
lISTINg 7-2: 
 Performing tasks using static methods
# Add the .NET Framework 2.0 to the path. 
import sys
sys.path.append(‘C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727’)
# Make clr accessible.
import clr
# Import the System assembly.
import System
# Get the system date and time.
CurrDateTime = System.DateTime.Now
# Display the date and time in a number of formats.
print ‘Short date and time:’ 
print System.DateTime.Now.ToShortDateString(),
print System.DateTime.Now.ToShortTimeString()
print ‘\nLong date and time:’ 
print CurrDateTime.ToLongDateString(),
print CurrDateTime.ToLongTimeString()
# Display a few statistics. 
print ‘\n Date Statistics:’ 
print ‘Days in Month:’, 
print CurrDateTime.DaysInMonth(CurrDateTime.Year, CurrDateTime.Month)
print ‘Daylight Savings?’, CurrDateTime.IsDaylightSavingTime() 
print ‘Leap Year?’, 
print CurrDateTime.IsLeapYear(CurrDateTime.Year)
# Manipulate the date. 
print ‘\nAdding a Day, Month, and Year:’
CurrDateTime = CurrDateTime.AddDays(1)
CurrDateTime = CurrDateTime.AddMonths(1)
CurrDateTime = CurrDateTime.AddYears(1)
print CurrDateTime.ToLongDateString()
# Pause after the debug session.
raw_input(‘Press any key to continue...’)
The code begins by adding the required 
sys.path
entry and importing the necessary modules and 
assemblies. It then creates a variable named 
CurrDateTime
, which is only in place for convenience. 
The code sets 
CurrDateTime
to reference 
System.DateTime.Now
. You can do the same thing with-
out relying on the variable.
The first outputs are the short and long date and time. Notice that the short date and time 
rely on 
System.DateTime.Now
, while the long date and time rely on 
CurrDateTime
. In both 
cases, the code calls on static methods to output the date and time in a specific format using 
ToShortDateString()

ToShortTimeString()

ToLongDateString()
, and 
ToLongTimeString()

Figure 7-12 shows the output from these calls.
548592c07.indd 131
2/25/10 9:44:29 AM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   143   144   145   146   147   148   149   150   ...   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