I’m trying to write something like:
class MyClass(object):
@staticmethod
def test(x, y, z=None):
if not z:
z = external_function(MyClass)
Is it possible in python to rewrite it to something like:
class MyClass(object):
@staticmethod
def test(x, y, z=external_function(MyClass)):
pass
(The second code does not work as it is referencing MyClass which is not defined at this point)
It is not possible to rewrite the code that way. The closest you can do is something like:
Note that this assumes Python 3; in Python 2, you may need to fiddle around with the
newmodule. But though this is possible, the intention of the code is very non-obvious. It is better to stick toif z is None, or to refactor your code to not need this.