Answers for "python override inherited method"

0

python override inherited method

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)
Posted by: Guest on May-02-2022
0

python override inherited method class model constructor

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)
Posted by: Guest on May-02-2022

Code answers related to "python override inherited method"

Python Answers by Framework

Browse Popular Code Answers by Language