argument type
Roy Smith
roy at panix.com
Tue Dec 28 17:17:00 EST 2004
"It's me" <itsme at yahoo.com> wrote:
> How can I tell from within a function whether a particular argument is a
> sigular type, or a complex type?
> ...
> 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 have a vague feeling you're trying to write C++ in Python, and that
usually doesn't work well. In general, C++ (and Java) is all about
types of things, while Python is more about capabilities of things.
What do you mean by a "simple type" as opposed to a "complex type"? I
suspect by "complex type" you really mean "tuple or list". If that's
the case, you can certainly do something like:
def myFunc (arg):
if isinstance (arg, tuple) or isinstance (arg, list):
blah, blah, blah
But before you do that, you might want to think if this is really what
you want to do. What, exactly, is it that you're trying to do that
requires you to know what type of object an argument is?
More information about the Python-list
mailing list