Python optional function argument to default to another argument's value
<p>I want to define a function with some optional arguments, let's say A (mandatory) and B (optional). When B is not given, I want it to take the same value as A. How could I do that?</p>

<p>I have tried this, but it doesn't work (name 'B' is not defined):</p>

<pre><code>def foo(A, B=A):
    do_something()
</code></pre>

<p>I understand that the values of the arguments are not assigned before the body of the function.</p>