Mar-20-2020, 01:21 AM
(This post was last modified: Mar-20-2020, 01:40 AM by wolfmansbrother.)
(Mar-19-2020, 10:08 PM)Larz60+ Wrote: have you tried to run this?
Class A: will cause a syntax error
class has no title case.
also closing parenthesis on lines 7 (both of them) are missing
No i did not try to run it, thought it sufficed to get my point accross.
(Mar-19-2020, 10:15 PM)scidam Wrote: You can define unbound method__init__
, e.g.
def unbound_init(s): s.phish = 'Band' # and create class instance (and the class) dynamically a_instance = type('A', (), {'__init__': unbound_init})() # or maybe you wish one-liner, a_instance = type('A', (), {'__init__': lambda self: setattr(self, 'phish', 'Band1')})()Now,a_instance.phish
isBand1
.
Thanks! This is going to be super useful <3