Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Python default arguments/attributes

Name: Anonymous 2013-03-07 15:23

Hey /prog/,
What's best practice when overriding defaults with arguments?

How do you do it?

Either way, it seems like a lot of boilerplate code.



class foo(object):
    bar = 5
    baz = 3


    def __init__(bar=None, baz=None, boo=1):

        # what if there are more possible values?
        self.bar = self.bar if bar is None else bar
       
        # what if baz isn't None, but evaluates to False?
        self.baz = baz or self.baz

        self.boo = boo

Name: Anonymous 2013-03-09 9:56

>>7
Bullshit. There's no case in which >>6 would not work.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List