import datetime
class Logger(object):
def log(self, message):
print message
class TimestampLogger(Logger):
def log(self, message):
message = "{ts} {msg}".format(ts=datetime.datetime.now().isoformat(),
msg=message)
super(TimestampLogger, self).log(message)
class Parent(object):
def __init__(self, a, b):
print 'a', a
print 'b', b
class Child(Parent):
def __init__(self, c, d, *args, **kwargs):
print 'c', c
print 'd', d
super(Child, self).__init__(*args, **kwargs)
test = Child(1,2,3,4)
class Bar(object):
def __init__(self, arg1=None, arg2=None, argN=None):
print arg1, arg2, argN
class Foo(Bar):
def __init__(self, my_new_arg=None, **kwds):
super(Foo, self).__init__(**kwds)
self.new_arg = my_new_arg
print my_new_arg
f = Foo(my_new_arg='x', arg2='y')
class Parent:
def __init__(self, common, data, **kwargs):
super().__init__(**kwargs)
self.common = common
self.data = data
@classmethod
def from_file(cls, filename, **kwargs):
# If the caller provided a data argument,
# ignore it and use the data from the file instead.
kwargs['data'] = load_data(filename)
return cls(**kwargs)
@classmethod
def from_directory(cls, data_dir, **kwargs):
return [cls.from_file(data_file, **kwargs)
for data_file in get_data_files(data_dir)]
class ChildA(Parent):
def __init__(self, specific, **kwargs):
super().__init__(**kwargs)
self.specific = specific