Ich möchte den Namen eines Attributs erhalten, während ich darüber iteriere.Name der Attribute
die ts3defines.py sieht aus wie this:
class VirtualServerProperties(object):
VIRTUALSERVER_UNIQUE_IDENTIFIER = 0
VIRTUALSERVER_NAME = 1
VIRTUALSERVER_WELCOMEMESSAGE = 2
VIRTUALSERVER_PLATFORM = 3
VIRTUALSERVER_VERSION = 4
VIRTUALSERVER_MAXCLIENTS = 5
VIRTUALSERVER_PASSWORD = 6
VIRTUALSERVER_CLIENTS_ONLINE = 7
VIRTUALSERVER_CHANNELS_ONLINE = 8
VIRTUALSERVER_CREATED = 9
VIRTUALSERVER_UPTIME = 10
VIRTUALSERVER_CODEC_ENCRYPTION_MODE = 11
VIRTUALSERVER_ENDMARKER = 12
die getItems(object)
Funktion sieht aus wie this:
def getItems(object):
return [getattr(object, a) for a in dir(object)
if not a.startswith('__') and not callable(getattr(object, a))]
der Code in Frage sieht aus wie this:
for var in getItems(ts3defines.VirtualServerProperties):
(err, var) = ts3.getServerVariable(schid, var)
if err == ts3defines.ERROR_ok and var != "" and var != 0:
i.append('{0}: {1}'.format(var.__name__, var))
Meine Frage ist über die var.__name__
sollte das nicht die Zeichenfolge VIRTUALSERVER_BLA
, etc?
Warum verursacht es?
11/25/2017 16:07:44 pyTSon.PluginHost.infoData Error Error calling infoData of python plugin Extended Info: Traceback (most recent call last):
File "C:/Users/blusc/AppData/Roaming/TS3Client/plugins/pyTSon/scripts\pluginhost.py", line 476, in infoData
data = p.infoData(schid, aid, atype)
File "C:/Users/blusc/AppData/Roaming/TS3Client/plugins/pyTSon/scripts\info\__init__.py", line 160, in infoData
return self.getServerInfo(schid)
File "C:/Users/blusc/AppData/Roaming/TS3Client/plugins/pyTSon/scripts\info\__init__.py", line 148, in getServerInfo
i.append('{0}: {1}'.format(var.__name__, var))
AttributeError: 'int' object has no attribute '__name__'
Was ist der 'var' Wert' ts3.getServerVariable (schid, var) 'kehrt? Im Allgemeinen haben Python-Objekte keine "__name__" -Attribute (zum Beispiel "int"), also warum erwartest du eine? – martineau