Professional IronPython


using Custom objects in IronPython



Download 20,35 Mb.
Pdf ko'rish
bet114/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   110   111   112   113   114   115   116   117   ...   453
using Custom objects in IronPython
At this point, you have a shiny new class named 
MyGreetings
. Normally, you won’t place the class 
and the code that uses it in the same file, so the example places the test code in 
TestFirstClass.py

Consequently, the first thing the example does is import 
MyGreetings
from 
FirstClass
, as shown 
in Listing 5-2.
lISTINg 5-2: 
 Testing the simple class
from FirstClass import MyGreetings
# Create an instance of the class.
TestIt = MyGreetings() 
# Set the Name attribute.
TestIt.Name = ‘George’
# Call the two methods.
TestIt.SayHello()
TestIt.SayGoodbye() 
# Pause after the debug session.
raw_input(‘Press any key to continue...’)
At this point, the code creates an instance of 
MyGreetings
and places it in 
TestIt
. Notice that the 
call to 
MyGreetings
doesn’t require any data. If you want to request data from the caller during 
instantiation, you must provide an 
__init__()
method in your class declaration. Otherwise, the 
interpreter provides a default declaration for you that creates the desired object.
The code changes the value of 
Name
by assigning a new value to it. Notice that you assign the new 
value to 
TestIt.Name
, just as you would in any other language.
Next, the code calls the two methods, 
SayHello()
and 
SayGoodbye()
. Notice that the method calls 
don’t require any input, and IronPython would complain if you tried to provide it. Remember that 
the interpreter provides 
self
in the background. Figure 5-2 shows the output from this application.
548592c05.indd 91
2/24/10 1:21:50 PM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   110   111   112   113   114   115   116   117   ...   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