Re: How can I verify that a passed argument is an interible collection?

2005-04-21 Thread John Machin
On Thu, 21 Apr 2005 09:59:54 -0500, Larry Bates <[EMAIL PROTECTED]> wrote: >2) Or if you not you could see if the argument has next and >__iter__ methods (more general solution) > >if hasattr(arg, 'next') and not hasattr(arg, '__iter__'): ># perform work on iterable > >else: >print "arg m

Re: How can I verify that a passed argument is an interible collection?

2005-04-21 Thread Steven Bethard
Charles Krug wrote: List: I'm working on some methods that operate on (mathematical) vectors as in: def Convolution(x, y) """Returns a list containing the convolution of vectors x and y""" Is there any way to determine at runtime that x and y are iterible collections? Do I *coughs* simply *coughs*

Re: How can I verify that a passed argument is an interible collection?

2005-04-21 Thread Diez B. Roggisch
Charles Krug wrote: > List: > > I'm working on some methods that operate on (mathematical) vectors as > in: > > def Convolution(x, y) > """Returns a list containing the convolution of vectors x and y""" > > Is there any way to determine at runtime that x and y are iterible > collections? > > D

Re: How can I verify that a passed argument is an interible collection?

2005-04-21 Thread Roy Smith
Charles Krug <[EMAIL PROTECTED]> wrote: > Do I *coughs* simply *coughs* trap the exception created by: > >for v in x: > >when v is a scaler quantity? Sure. Why not? If you're coming from a type-bondage language like C++ or Java, it probabliy feels strange, but it's the Python way. It looks

Re: How can I verify that a passed argument is an interible collection?

2005-04-21 Thread Larry Bates
Others may know better ways but the 2 I know of are: 1) If you know that the arguments will be lists or tuples you can use isinstance(). if not isinsance(arg, (list, tuple): print "arg must be list or tuple) 2) Or if you not you could see if the argument has next and __iter__ methods (more g

Re: How can I verify that a passed argument is an interible collection?

2005-04-21 Thread Fredrik Lundh
Charles Krug wrote: I'm working on some methods that operate on (mathematical) vectors as in: def Convolution(x, y) """Returns a list containing the convolution of vectors x and y""" Is there any way to determine at runtime that x and y are iterible collections? Do I *coughs* simply *coughs* trap t

How can I verify that a passed argument is an interible collection?

2005-04-21 Thread Charles Krug
List: I'm working on some methods that operate on (mathematical) vectors as in: def Convolution(x, y) """Returns a list containing the convolution of vectors x and y""" Is there any way to determine at runtime that x and y are iterible collections? Do I *coughs* simply *coughs* trap the excepti