Online Shopping : Computers : Programming : Languages : Python : Snippets

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 7 people (86%) answered Yes
Recently 5 of 6 people (83%) answered Yes

Entry

Passing keyword arguments from one method to another

Jul 5th, 2000 10:00
Nathan Wallace, Hans Nowak, Snippet 141, Python FAQ


"""
Packages: faq;oop
"""

"""
4.76. How do I pass keyword arguments from one method to another?

Use apply. For example: 
"""

class Account:
    def __init__(self, **kw):
        self.accountType = kw.get('accountType')
        self.balance = kw.get('balance')

class CheckingAccount(Account):
    def __init__(self, **kw):
        kw['accountType'] = 'checking'
        apply(Account.__init__, (self,), kw)

myAccount = CheckingAccount(balance=100.00)