Source From Here
Question
Suppose o is a Python object, and I want all of the fields of o, without any methods or __stuff__. How can this be done?
How-To
You can get it via the __dict__ attribute, or the built-in vars function, which is just a shortcut. For example:
Then you can try below samples:
Question
Suppose o is a Python object, and I want all of the fields of o, without any methods or __stuff__. How can this be done?
How-To
You can get it via the __dict__ attribute, or the built-in vars function, which is just a shortcut. For example:
- class A:
- V1="V1"
- def __init__(self):
- self.v1="v1"
- def hello(self):
- print "Hello"
沒有留言:
張貼留言