SORU
8 Mart 2010, PAZARTESİ


Süper Python kurucu çağırmak

class A:
 def __init__(self):
   print "world"

class B(A):
 def __init__(self):
   print "hello"

B()
hello

Tüm süper yapıcı beraber çalıştığım diğer diller örtülü olarak çağrılır. Nasıl bir Python çağırmak mı? super(self) beklerdim ama bu işe yaramıyor

CEVAP
8 Mart 2010, PAZARTESİ


super() ebeveyn-gibi bir nesne döndürüryeni-stil sınıfları:

class A(object):
 def __init__(self):
   print "world"

class B(A):
 def __init__(self):
   print "hello"
   super(B, self).__init__()

B()

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • mahalodotcom

    mahalodotcom

    8 HAZİRAN 2007
  • Matus Slovak

    Matus Slovak

    5 Temmuz 2007
  • theavettbrothers

    theavettbrot

    9 ŞUBAT 2007