[Tutor] How do I do this in python?
Robert Lummis
robert.lummis at gmail.com
Thu Jun 11 03:43:33 CEST 2009
I want to write a function that I can use for debugging purposes that
prints the values of whatever list of object references it is given as
arguments, without knowing in advance how many object references it
will be called with or what they might be. For example, the call:
show(a,b,c) would output the values of the arguments like this:
a = 3
b = 'john'
c = 'Monday'
while show (x) would output (for example):
x = 3.14
of course displaying whatever the actual current values are. For a
collection object it would make sense to output just the first few
values.
So within the 'show' function definition I have to somehow get a list
of the literal argument names it was called with and then use the
names as globals to get the values. How do I do that?
If this can't be done but there is a completely different way to
achieve a similar result, what is it?
I'm trying to learn python but it's a struggle because the
documentation is so dispersed. If there is a solution to this
question, what documentation could I have looked at to find it on my
own?
BTW I'm using python 3.01 if it matters.
--
Robert Lummis
More information about the Tutor
mailing list