从字典中删除属性

Deleting attribute from Dictionary

我需要从 Dictionary 对象中删除一个属性。我正在尝试使用 "del," 执行此操作,但它对我不起作用。

from suds.client import Client
from sys import argv

cmserver = '***my-server-host-name***'
cmport = '8443'
wsdl = 'file:///code/AXL/axlsqltoolkit/schema/10.5/AXLAPI.wsdl'
location = 'https://' + cmserver + ':' + cmport + '/axl/'
username = argv[1]
password = argv[2]

client = Client(url=wsdl,location=location, username=username, password=password)
result = client.service.getPhone(name='SEP64AE0CF74D0A')
del result['_uuid']

代码失败:

Traceback (most recent call last):
  File "AXL-Get-Phone.py", line 27, in <module>
    del result['_uuid']
AttributeError: __delitem__

示例 [print(str(result))] 对象的输出我试图从以下位置删除“_uuid”:

(reply){
    return = 
        (return){
            phone = 
                (RPhone){                   
                     _uuid = "{D1246CFA-E02D-0731-826F-4B043CD529F1}"

首先,您需要将结果转换为 dict。有一个 suds.client.Client class 方法 dict 可以为您完成此操作。请参阅 suds.client.Client.

的文档
result = Client.dict(client.service.getPhone(name='SEP64AE0CF74D0A'))
del result['_uuid']

此外,您可以简单地删除 _uuid 属性,例如:

result = client.service.getPhone(name='SEP64AE0CF74D0A')
del result._uuid