≈ the.bay.news

Using exec to define a member function that uses super()

Discussions on Python.org
Using exec to define a member function that uses super()
Suppose I am defining a class. This works: class Foo: exec('def f(self): pass') However, things go wrong if the function defined that way uses super(): class Base: pass class Derived(Base): exec('def f(self): super()') >>> Derived().f() Traceback (most recent call last): File "<python-input-1>", line 1, in <module> Derived().f() ~~~~~~~~~~~^^ File "<string>", line 1, in f RuntimeError: super(): __class__ cell not found It’s not wrong: Derived.f.__code__.co_freevars i...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.