Co-dependent default arguments
Question: I have code like so:

    
    
    import random
    
    def helper():
        c = random.choice([False, True]),
        d = 1 if (c == True) else random.choice([1, 2, 3])
        return c, d
    
    class Cubic(object):
        global coefficients_bound
    
        def __init__(self, a = random.choice([False, True]), 
            b = random.choice([False, True]),
            (c, d) = helper()):
            ...
            ...
    

The helper() function is introduced as I cannot have co-dependent arguments in
the definition of the function itself - Python complains that it cannot find c
when it's calculating d.

I want to be able to create an object of this class like so, changing a
default argument:

    
    
    x = Cubic(c = False)
    

But I get this error:

    
    
    Traceback (most recent call last):
      File "cubic.py", line 41, in <module>
        x = Cubic(c = False)
    TypeError: __init__() got an unexpected keyword argument 'c'
    

Is this possible with how I've written it? If not, what way should I do this?


Answer: How about simply:

    
    
    class Cubic(object):
        def __init__(self, c=None, d=None):
            if c is None:
                c = random.choice([False, True])
            if d is None:
                d = 1 if c else random.choice([1, 2, 3])
            print c, d
    

