argument type

It's me itsme at yahoo.com
Tue Dec 28 00:08:49 EST 2004


Donn,

That would lead to program error easily because when one forgets to include
the needed [], you get unintended result from the program.

I am going to try the "isinstance" approach mentioned by Brian.

Thanks,

"Donn Cave" <donn at drizzle.com> wrote in message
news:41d0dbf7$1_1 at 127.0.0.1...
> Quoth "It's me" <itsme at yahoo.com>:
> | A newbie question.
> |
> | How can I tell from within a function whether a particular argument is a
> | sigular type, or a complex type?
> |
> | For instance, in:
> |
> |     def abc(arg1)
> |
> | How do I know if arg1 is a single type (like a number), or a list?
> |
> | In C++, you would do it with function overloading.  If arg1 is always
simple
> | type, I wouldn't care what it is.  But what if I *do* need to know
whether
> | arg1 is a list or not?
> |
> | I hate to have to have 2 functions: 1 for simple types, and one for list
> | types and then do something like:
> |
> |     abc_simple(1.0)
> |     abc_list([1.0,2.0])
> |
> | Any help would be greatly appreciated.
>
> How about abc([1.0])?  That's easy, and it's a lot cleaner than
> mucking up your API with functions whose parameters have multiple
> possible interpretations.  C++ doesn't always point the way to
> great programming models.
>
> Donn Cave, donn at drizzle.com





More information about the Python-list mailing list