例如我得到了Link类:
class link(object):
def __init__(self, url, title, visited=False):
self.url = url
self.title = title
self.visited = visited
我希望将它扩展到另外还有一个字段的ArticleLink类 - 日期(伪代码):
class articleLink(link):
def __init__(self,<i want to avoid typing it all again>, date):
super(articleLink, self).__init__(<what to type here?>)
self.date = date
我在想什么/如何正确地做到这一点?
答案 0 :(得分:0)
你可以这样做:
# Note this function requires exactly three arguments
def my_method(x,y,z):
print 'x: %s, y: %s, z: %s'
class MyClass:
def __init__(self, *my_args ):
my_method( *my_args )
myClass = MyClass( 'x', 'y', 'z' )
# will print "x: x, y: y, z:z"
但这有点神秘。