0

In python, I am trying to do the following

def my_function(foo, bar = 1, baz = my_second_function(foo)):

that is foo is mandatory, and the default value of baz is a function of foo.

I get a NameError: name 'foo' is not defined

I thought I could do something like

def my_function(foo, bar = 1, baz = None):
    if baz is None:
        baz = my_second_function(foo)

Is it the pythonic or correct way to do it?

Meth
  • 189
  • 6

0 Answers0