Author Dusty Phillips Reviewers



Download 2,95 Mb.
Pdf ko'rish
bet130/183
Sana20.07.2022
Hajmi2,95 Mb.
#831085
1   ...   126   127   128   129   130   131   132   133   ...   183
Bog'liq
python3-oop

[
 133 
]
This 
property
constructor can actually accept two additional arguments, a deletion 
function and a docstring for the property. The 
delete
function is rarely supplied in 
practice, but it can be useful for logging that a value has been deleted, or possibly 
to veto deleting if we have reason to do so. The docstring is just a string describing 
what the property does, no different from the docstrings we discussed in 
Chapter 2

Objects in Python
. If we do not supply this parameter, the docstring will instead be 
copied from the docstring for the first argument: the getter method. Here is a silly 
example that simply states whenever any of the methods are called:
class Silly:
def _get_silly(self):
print("You are getting silly")
return self._silly
def _set_silly(self, value):
print("You are making silly {}".format(value))
self._silly = value
def _del_silly(self):
print("Whoah, you killed silly!")
del self._silly
silly = property(_get_silly, _set_silly,
_del_silly, "This is a silly property")
If we actually use this class, it does indeed print out the correct strings when we
ask it to:
>>> s = Silly()
>>> s.silly = "funny"
You are making silly funny
>>> s.silly
You are getting silly
'funny'
>>> del s.silly
Whoah, you killed silly!
Further, if we look at the help file for the 
Silly
class (by issuing 
help(silly)
at
the interpreter prompt), it shows us the custom docstring for our 
silly
attribute:
Help on class Silly in module __main__:
class Silly(builtins.object)
www.it-ebooks.info


When to Use Object-oriented Programming

Download 2,95 Mb.

Do'stlaringiz bilan baham:
1   ...   126   127   128   129   130   131   132   133   ...   183




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