Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)
Comment

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)
Comment

python override inherited method class model constructor

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')
Comment

PREVIOUS NEXT
Code Example
Python :: # convert dictionary keys to a list 
Python :: turn dictionary into flat list 
Python :: discord python bot input 
Python :: python mysqldb sockets 
Python :: complete dates pandas per group by 
Python :: penggunaan items di python 
Python :: python truncade number 
Python :: Concatenation of two range() functions 
Python :: django hash password Argon 
Python :: unauthorized vue django rest framework 
Python :: download Twitter Images with BeautifulSoup 
Python :: python Tkinter widget displacement with pack() 
Python :: how to create function python 
Python :: python code sample submission of codeforces 
Python :: separete even and odd numbers from a list by filter in python 
Python :: string exercise 
Python :: Deploying matlab app on the web using python 
Python :: typing effect in python 
Python :: np sign no 0 
Python :: replace string in dictionary python 
Python :: plt datas use left and right yaxes 
Python :: python data statics 
Python :: mehrzeiliges kommentar python 
Python :: get most recurring element in a list python 
Python :: downloading datasets from ml.org repository 
Python :: separate array along axis 
Python :: voilion plot 
Python :: qcombobox remove all items 
Python :: count items in a model django rest 
Python :: pip install rejson 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =