J
Josef Dalcolmo
If I have a Python variable like
var = 33
can I get the name 'var' as a string?
Obviously this does not make much sense when using a single variable, but if I want to print the variable together with it's name, for a list of variables, then it could make sense:
def printvariables(varlist):
.....for var in varlist:
.........print var.__name__, var
of course the attribute __name__ I just made up, and if this would always return 'var' it would not make any sense either.
I am not sure if such a thing is at all possible in Python.
Best regards - Josef Dalcolmo
var = 33
can I get the name 'var' as a string?
Obviously this does not make much sense when using a single variable, but if I want to print the variable together with it's name, for a list of variables, then it could make sense:
def printvariables(varlist):
.....for var in varlist:
.........print var.__name__, var
of course the attribute __name__ I just made up, and if this would always return 'var' it would not make any sense either.
I am not sure if such a thing is at all possible in Python.
Best regards - Josef Dalcolmo