當對象屬性的名稱中含有冒號時,如何使用屬性?在那裏我碰到這種形勢下應運而生的代碼是:如何使用在ite名稱中冒號的屬性
instances = nova.servers.list()
for i in instances:
print i.id, i.OS-EXT-SRV-ATTR:hypervisor_hostname
看鏈接Find All Elements Given Namespaced Attribute和How do I escape a colon in Python format() when using kwargs? 之後,我嘗試使用ATTR作爲
instances = nova.servers.list()
for i in instances:
print i.id, i.(attr={"OS-EXT-SRV-ATTR":"hypervisor_hostname"})
但它給錯誤的語法無效。我應該如何使用屬性OS-EXT-SRV-ATTR:hypervisor_hostname
你怎麼能夠__set__具有這樣的名字的屬性? – warvariuc
我很感興趣,爲什麼你想這樣做。 – ebarr