我希望在迭代它时获取任何属性的名称。
ts3defines.py看起来像this:
get report C
*** Test Cases ***
Test Report A
${result} = get report A
LOG Result: ${result} console=${TRUE}
函数看起来像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
有问题的代码看起来像this:
getItems(object)
我的问题是关于def getItems(object):
return [getattr(object, a) for a in dir(object)
if not a.startswith('__') and not callable(getattr(object, a))]
不应该返回字符串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))
等?
为什么会这样?
var.__name__
答案 0 :(得分:2)
我不明白你为什么试图访问 public class PoleTrailInstantiation : MonoBehaviour
*//variables....*
public GameObject Pole; *// object that would be instantiated, contains a trigger set to certain radius that prevents object instantiation and is tagged "CreatedPole"*
public Transform polePosition;
public Transform CreatorObject; *//empty object inside of player where "poles" are instantiated, this is where script is attached*
public GameObject Player;
private bool insideTrigger = false; *//this will tell me if I left trigger and instantiation would be allowed*
// Update is called once per frame
void FixedUpdate() *// this works only in fixedUpdate*
{
if ((Input.GetKey(KeyCode.Space) && isInsideTrigger == false))
{
InstantiatePole(); *// function that creates objects - "poles"*
}
insideTrigger = false;
} //end of FixedUpdate
private void OnTriggerStay(Collider other)
{
if (other.gameObject.CompareTag("CreatedPole")) *//compares if trigger player stays in belongs to "createdPole" object)*
{
insideTrigger = true;
print("OnTriggerStay activated!");
}
}
。您已在__name__
方法中拥有该名称;它是getItems
。你应该返回它并在循环中使用它。
a
...
def getItems(object):
return [(a, getattr(object, a)) for a in dir(object)
if not a.startswith('__') and not callable(getattr(object, a))]