x.methods['m1'] instead of so that I can run the method, but I get an error.(
x=test()I would like to specify a key like ()
NameError: name'self' is not defined)
How should I change it?python
Is it meaningful to do that?I think there are some unexpected restrictions on how to use it, but I can think of setting it in this pattern.
There seems to be still a way to do it, but let me give you an example.
_init__Configure with the method
methodsis also an instance variable
self.when configuring (=parameter the instance as self when calling)
The following is how to use properties:
The error occurs because
self is not defined in the location where
self.method1 is written.
Python's various embedded functions allow you to automatically list the methods defined in the class.
It depends on what you want to do, but if you create a key name generation rule, you may be able to do what you want to do.
© 2022 OneMinuteCode. All rights reserved.