sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #15756
Re: [Question #187286]: How get tuple name ?
Question #187286 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/187286
RaiMan posted a new comment:
There is no feature in Python, to get the name of a variable as a string.
But in your case you might use this hack, that uses the id of an object to find it in globals().
# returns the tuple's name, if it is one, otherwise empty string
def getNameOfTuple(p):
for k,v in globals().items():
if not isinstance(v, tuple): continue
if not id(p) == eval("id(%s)"%k): continue
return k
return ""
-- usage
variable = "not a tuple"
someTuple = (1,2,3)
print "name=", getNameOfTuple(someTuple)
#prints: name= someTuple
print "name=", getNameOfTuple(variable)
#prints: name=
BTW: if there is a better way to get name of tuple without parse all existing one knowing I have hundreds. of them
Forget about this, just do it ;-) Python interpreter does this ten or even hundred times more often than you ;-)
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.