python - Pythonic switching using functions inside a class -
i attempting utilize dict command function selection within class, however, next typeerror:
typeerror: a() missing 1 required positional argument: 'self'
example code:
class tt: def __init__(self): pass def a(self): print("a") def b(self): print("b") def c(self): print("c") a_diction={ '0' : a, '1' : b, '2' : c } def ad(self,data): self.a_diction[data]()
how should build switch in ad
provide self
both a_diction
, called method a
, b
, c
?
the error message indicates you're missing argument. suggest adding argument.
self.a_diction[data](self)
python class switch-statement
No comments:
Post a Comment