| | |
super function
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 3
Reputation:
Solved Threads: 0
Python Syntax (Toggle Plain Text)
class x(object): def __init__(self): self.x=1 class y(x): def __init__(self): super(y, self).__init__()
•
•
Join Date: Jul 2006
Posts: 608
Reputation:
Solved Threads: 150
The super() function allows you to access methods in the parent x that are shadowed by methods of the same name in the child y.
In this case, y.__init__ wants to call x.__init__. But the problem is that y.__init__ clobbers __init__ in the namespace; that is, x.__init__ doesn't get inherited. SO, super(y, self) returns x, so that your code means this:
Jeff
In this case, y.__init__ wants to call x.__init__. But the problem is that y.__init__ clobbers __init__ in the namespace; that is, x.__init__ doesn't get inherited. SO, super(y, self) returns x, so that your code means this:
Python Syntax (Toggle Plain Text)
class x(object): def __init__(self): self.x=1 class y(x): def __init__(self): x.__init__(self)
Jeff
![]() |
Similar Threads
- Function that returns void (C++)
- How to develop a new program (C++)
- What super power would you most likely want? (Geeks' Lounge)
Other Threads in the Python Forum
- Previous Thread: Error while opening a file
- Next Thread: where is the bug in this code???
| Thread Tools | Search this Thread |
abrupt ansi anti apache approximation array assignment backend beginner binary book builtin calculator character code converter countpasswordentry curved customdialog dan08 dictionaries dictionary drive dynamic examples exe file float format function graphics gui heads homework ideas import inches input java launcher library line lines linux list lists loop mouse mysql mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame pysimplewizard python random recursion redirect scrolledtext software statictext statistics string strings sum table terminal text textarea thread threading time tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable windows wordgame write wxpython





