Function call as a default function argument

Viewed 87

Having

# example.py

def foo(arg=bar()):
        pass

will execute bar even with from example import foo.

I remember that long time ago I saw something like:

# example.py

def foo(arg=lambda: bar()):
        pass

but I'm not sure if it's the best way and now, when I am stuck with this, I can't find any info on how to deal with this behaviour.

What is the correct way to have function call as a default function argument in python?

1 Answers
Related