This works to pass a variable number of arguments, except in the
case of NO arguments, which generates an error. Is there any way
around this other than wrapping a try:except: around it to catch
the type error for zero arguments ?
>>> def who( x ):
... print type( x )
... if type(x) <> type( () ): #this takes care of CASE 1
... x = x,
... print len(x)
... print x
...
>>> who( 1,2,3 )
<type 'tuple'>
3
(1, 2, 3)
>>> who( 1, ) # CASE 1: tuple of len = 1
<type 'tuple'>
1
(1,)
>>> who( 1 ) # CASE 1:
<type 'int'> # coerced into a tuple.
1
(1,)
>>> who( () ) # CASE 0:
<type 'tuple'>
0
()
>>> who( )
Unhandled exception: type error: function expects argument(s)
Stack backtrace (innermost last):
File "<stdin>", line 1
File "<stdin>", line 1
======== "If you have a hammer, find a nail" - George Bush,'91 =========
Steven D. Majewski University of Virginia Physiology Dept.
sdm7g@Virginia.EDU Box 449 Health Sciences Center
Voice: (804)-982-0831 1600 Jefferson Park Avenue
FAX: (804)-982-1616 Charlottesville, VA 22908