0

我正在尝试在 pysphere 中使用 VIProperty,但我得到'str' object has no attribute 'typecode'

代码:

for h, mor in server.get_hosts().items():
    if mor == 'xxx.com':
        prop = VIProperty(server, mor)

错误:

Traceback (most recent call last):
  File "teardown.py", line 29, in <module>
    prop = VIProperty(server, mor)
  File "/usr/local/lib/python2.7/dist-packages/pysphere/vi_property.py", line 38, in __init__
    self._type = obj.typecode.type[1]
AttributeError: 'str' object has no attribute 'typecode'
4

1 回答 1

-1

工作正确,因为 "mor" 仍然是字符串类型,而'str' 对象没有属性 'typecode'

VI属性

class VIProperty(object):
    def __init__(self, server, obj):
        self._server = server
        self._obj = obj
        self._values_set = False
        self._type = obj.typecode.type[1]

你的调用方法:

for h, mor in server.get_hosts().items():
    if mor == 'xxx.com':
        print type(mor) # <<<< 'str'
        prop = VIProperty(server, mor)

试试看:

    hosts = server.get_hosts()
    for hmor, hname in hosts.items():
        if hname == 'xxx.com':
           p = VIProperty(server, hmor)
于 2016-11-28T16:36:46.530 回答