Hey,
I am trying to write a function that takes an arbitrary number of
arguments and does one of two things. If the variable is a key in a
dictionary, it prints the key and its value. Otherwise, if any of the
variables isn't in the dictionary, the function prints the variable's
name and value.
as you have been told, there is no way to get a variable's name, take a
look at http://effbot.org/zone/python-objects.htm to find out why this
is so.
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] a écrit :
Hey,
I am trying to write a function that takes an arbitrary number of
arguments and does one of two things. If the variable is a key in a
dictionary, it prints the key and its value. Otherwise, if any of the
variables isn't in the dictionary, the function
Bruno Desthuilliers wrote:
[EMAIL PROTECTED] a écrit :
globals = {}
globals() is a builtin function, you should no shadow it.
Oh, woops. I'll fix that.
def printVerbose(*args, **kwargs):
if VERBOSE in globals:
for a in args:
if a in globals:
Simon Dahlbacka wrote:
as you have been told, there is no way to get a variable's name, take a
look at http://effbot.org/zone/python-objects.htm to find out why this
is so.
Thanks, Simon, for the link.
--
Regards,
Travis Spencer
--
http://mail.python.org/mailman/listinfo/python-list
Simon Dahlbacka wrote:
as you have been told, there is no way to get a variable's name
Well, if you really want to, you can get all the names bound to a given
object:
def get_names(obj):
g = globals()
names = []
for name in g:
if g[name] is obj:
[EMAIL PROTECTED] wrote:
Bruno Desthuilliers wrote:
def printVerbose(*args, **kwargs):
if VERBOSE in globals:
for a in args:
if a in globals:
value = globals[a]
for k, v in kwargs.iteritems():
print %s: %s %