2016-11-28 21 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) 

エラー: "MOR" STIL文字列型と'str' はオブジェクトが属性の型コード "を持っていないので、

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

がcurrect動作します。

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?コメントやフィードバックなしで –

関連する問題