有没有办法在Python中确定对象是否具有某些属性?例如:
>>> a = SomeClass()
>>> a.someProperty = value
>>> a.property
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: SomeClass instance has no attribute 'property'
Run Code Online (Sandbox Code Playgroud)
在使用之前如何判断是否a具有该属性property?
Python中"iterable","iterator"和"iteration"的最基本定义是什么?
我已阅读多个定义,但我无法确定其确切含义,因为它仍然不会沉入其中.
有人可以帮助我解释外行人的3个定义吗?
Python中是否有内置方法来获取所有类的实例变量的数组?例如,如果我有这个代码:
class hi:
def __init__(self):
self.ii = "foo"
self.kk = "bar"
Run Code Online (Sandbox Code Playgroud)
有没有办法让我这样做:
>>> mystery_method(hi)
["ii", "kk"]
Run Code Online (Sandbox Code Playgroud)
编辑:我原本错误地要求类变量.