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 10:54

>>7
boxed type
Python
And condescending "but knows too little Python to ask it correctly" makes your comment a work of art.
>>8
Well, strictly speaking, what if OP is in a habit of changing default values at runtime while he gorges on an enormous penis?

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