Re: About __init__ and default arguments

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott David Daniels

    Re: About __init__ and default arguments

    Nathan Duran wrote:
    >
    On Apr 11, 2008, at 11:35 AM, python-list-request@python. org wrote:
    >I'd like to assign the value of an attribute in __init__ as the default
    >value of an argument in a method. See below:
    Why not just do
    >
    def franklin(self, keyword):
    if not keyword: keyword = self.default
    return "A %s in time saves nine." % (keyword)
    Several things are false (for example: '', 0, False, [], ...)
    If you can get along with the code you have suggested, I'd
    think about using:

    def franklin(self, keyword):
    return "A %s in time saves nine." % (keyword or self.default)

    -Scott David Daniels
    Scott.Daniels@A cm.Org
Working...