Why doesn't the following work in Python?
def make_class(a):
class A(object):
a=a
return A
works just fine:
>>> def make_class(a):
class A(object):
_a=a
return A
>>> make_class('df')
<class '__main__.A'>
>>> make_class('df')._a
'df'
btw, function is not a reserved keyword in Python.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With