Little Q: how to print a variable's name, not its value?
Bill Mill
bill.mill at gmail.com
Tue Mar 29 11:23:45 EST 2005
On Tue, 29 Mar 2005 14:34:39 GMT, Ron_Adam <radam2 at tampabay.rr.com> wrote:
> On 28 Mar 2005 23:01:34 -0800, "Dan Bishop" <danb_83 at yahoo.com> wrote:
>
> >>>> def print_vars(vars_dict=None):
> >... if vars_dict is None:
> >... vars_dict = globals()
> >... for var, value in vars_dict.items():
> >... print '%s = %r' % (var, value)
> >...
> >>>> myPlace = 'right here'
> >>>> myTime = 'right now'
> >>>> print_vars()
> >print_vars = <function print_vars at 0x401e0d84>
> >__builtins__ = <module '__builtin__' (built-in)>
> >myTime = 'right now'
> >myPlace = 'right here'
> >__name__ = '__main__'
> >__doc__ = None
>
> Fred = 5
> John = 8
> Winner = John
>
> Both John and Winner are pointing to the literal '8'.
ummm, yes, of course they are. What's your point?
>
> Mixing data and program code, ie.. variable names as data, is not a
> good idea.
Down with eval! Exile exec! A pox on both their houses!
(i.e. I respectfully disagree that mixing data with program code is a bad idea)
Peace
Bill Mill
bill.mill at gmail.com
More information about the Python-list
mailing list