प्रतीत होता है A.__repr__()
और dict.__str__()
क्यों नीचे दिए गए उदाहरण में?पायथन बेस क्लास विधि कॉल: अप्रत्याशित व्यवहार
class A(dict):
def __repr__(self):
return 'repr(A)'
def __str__(self):
return dict.__str__(self)
class B(dict):
def __str__(self):
return dict.__str__(self)
print 'call: repr(A) expect: repr(A) get:', repr(A()) # works
print 'call: str(A) expect: {} get:', str(A()) # does not work
print 'call: str(B) expect: {} get:', str(B()) # works
आउटपुट:
call: repr(A) expect: repr(A) get: repr(A)
call: str(A) expect: {} get: repr(A)
call: str(B) expect: {} get: {}
http://www.python.org/dev/peps/pep-3140/ – bernie