我必须编写一个测试模块并具有 c++-Background。也就是说,我知道python中没有指针,但我如何实现以下目标:
我有一个测试方法,它看起来像这样的伪代码:
def check(self,obj,prop,value):
if obj.prop <> value: #this does not work,
#getattr does not work either, (objects has no such method (interpreter output)
#I am working with objects from InCyte's python interface
#the supplied findProp method does not do either (i get
#None for objects I can access on the shell with obj.prop
#and yes I supply the method with a string 'prop'
if self._autoadjust:
print("Adjusting prop from x to y")
obj.prop = value #setattr does not work, see above
else:
print("Warning Value != expected value for obj")
因为我想在不同的函数中检查许多不同的对象,所以我希望能够保留检查方法。
一般来说,如何确保函数影响传递的对象并且不创建副本?
myobj.size=5
resize(myobj,10)
print myobj.size #jython =python2.5 => print is not a function
我无法调整成员方法的大小,因为myobj
实现遥不可及,而且我不想myobj=resize(myobj, 10)
到处打字
另外,我怎样才能使我可以访问传递对象和属性名称的函数中的那些属性?