首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AttributeError:'str‘对象没有属性'typecode’

AttributeError:'str‘对象没有属性'typecode’
EN

Stack Overflow用户
提问于 2016-11-28 16:24:18
回答 1查看 818关注 0票数 0

我试图在pysphere中使用VIProperty,但我得到的是'str‘对象没有属性'typecode'

代码:

代码语言:javascript
复制
for h, mor in server.get_hosts().items():
    if mor == 'xxx.com':
        prop = VIProperty(server, mor)

错误:

代码语言:javascript
复制
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'
EN

回答 1

Stack Overflow用户

发布于 2016-11-28 16:36:46

因为"mor“string类型和'str‘对象没有属性'typecode',所以可以使用currect。

VIProperty

代码语言:javascript
复制
class VIProperty(object):
    def __init__(self, server, obj):
        self._server = server
        self._obj = obj
        self._values_set = False
        self._type = obj.typecode.type[1]

你的呼叫方法:

代码语言:javascript
复制
for h, mor in server.get_hosts().items():
    if mor == 'xxx.com':
        print type(mor) # <<<< 'str'
        prop = VIProperty(server, mor)

试一试:

代码语言:javascript
复制
    hosts = server.get_hosts()
    for hmor, hname in hosts.items():
        if hname == 'xxx.com':
           p = VIProperty(server, hmor)
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40849034

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档