2016-11-28 81 views
0

我想在pysphere中使用VIProperty,但我得到'str'對象沒有屬性'typecode'AttributeError:'str'對象沒有屬性'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' 

回答

-1

作品當期的,因爲 「鐵道部」 史迪威字符串類型和'海峽' 對象有沒有屬性 '類型代碼'

VIProperty

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) 
+0

好呀! DwnVote爲了什麼?沒有任何評論或反饋 –