First, I have two classes like this:
class A(object):
def foo(self, context):
print(context)
class B(object):
def foo(self, context):
print(context)
Notice the context
variable here.
Second, I want to call A and B in exec like this:
body = """
a = A()
a.foo()
b = B()
b.foo()
"""
exec(body)
I also have some other classes which use context
.
Which means that I don't want the context
variable appeared in the body
code. It's been generated in other place. And I want to send it by exec or other methods.
So how can I do this?