Source code online books for professionals by professionals


BLaCK BOX: tOpOLOGICaL SOrtING aND pYthON’S MrO



Download 4,67 Mb.
Pdf ko'rish
bet63/266
Sana31.12.2021
Hajmi4,67 Mb.
#213682
1   ...   59   60   61   62   63   64   65   66   ...   266
Bog'liq
2 5296731884800181221

BLaCK BOX: tOpOLOGICaL SOrtING aND pYthON’S MrO
the kind of structural ordering we’ve been working with in this section is actually an integral part of python 
object-oriented inheritance semantics. For single inheritance (each class is derived from a single superclass), 
picking the right attribute or method to use is easy. simply walk upward in the “chain of inheritance,” first 
checking the instance, then the class, then the superclass, and so forth. the first class that has what we’re 
looking for is used.
however, if you can have more than one superclass, things get a bit tricky. Consider the following example:
 
>>> class X: pass
>>> class Y: pass
>>> class A(X,Y): pass
>>> class B(Y,X): pass
 
If you were to derive a new class 
C
 from 
A
 and 
B
, you’d be in trouble. You wouldn’t know whether to look for 
methods in 
X
 or 
Y
.
In general, the inheritance relationship forms a daG (you can’t inherit in a cycle), and in order to figure out where 
to look for methods, most languages create a linearization of the classes, which is simply a topological sorting 
of the daG. recent versions of python use a method resolution order (or Mro) called C3 (see the references for 
more information), which in addition to linearizing the classes in a way that makes as much sense as possible 
also prohibits problematic cases such as the one in the earlier example.


Chapter 4 

 InduCtIon and reCursIon ... and reduCtIon 
85

Download 4,67 Mb.

Do'stlaringiz bilan baham:
1   ...   59   60   61   62   63   64   65   66   ...   266




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