我在这件事上已经有一段时间了。我无法访问对象属性的值,但console可以很好地打印名称。属性的名称和数量需要是动态的,并且根据它们来自哪个源而变化。因此,我不能只使用一致的方法。在
starting_list = ["Comapny", "Contact Name", "Email", "Phone", "URL", "Country", "Source"]
class NewClass(object):
_myattrib = None
def __setattr__(self, prop, val):
super().__setattr__('myattrib', val)
print("setting myattrib")
def __init__(self):
for item in starting_list:
#cleaning up a bit
item = str(item)
item = item.lower()
item = item.strip()
item = item.replace(' ', '_')
self.__setattr__(self, item, 'hi')
print(item) #it reads it here
print(NewClass.url)
任何帮助都会很感激的。在
我将更新objects
__dict__
属性,而不是乱弄__setattr__
编辑:为便于阅读,将一些行拆分
相关问题 更多 >
编程相关推荐