[Tutor] How do I do this in python?
The Green Tea Leaf
thegreentealeaf at gmail.com
Thu Jun 11 12:56:27 CEST 2009
My advice: "Learning Python" very nice book
def show(*args):
print args
def show2(*args):
for item in args:
print "Blabla:",item
show(1,2,"hello")
show2(1,2,"hello")
On Thu, Jun 11, 2009 at 03:43, Robert Lummis<robert.lummis at gmail.com> wrote:
> 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
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
--
The Green Tea Leaf thegreentealeaf at gmail.com thegreentealeaf.blogspot.com
More information about the Tutor
mailing list