Re: Checking length of each argument - seems like I'm fighting Python

2005-12-04 Thread Brendan
Thank you all for your help. Alex's listify does the job well. I will reconsider using an atomic "Thing" class with Michaels' safeList. Bengt wins the prize for reducing sLen to one line! I still feel like I'm working against the grain somewhat, (Mike's right, I am coming at this with a "C++ min

Re: Checking length of each argument - seems like I'm fighting Python

2005-12-03 Thread Bengt Richter
On 3 Dec 2005 15:50:25 -0800, "Brendan" <[EMAIL PROTECTED]> wrote: >There must be an easy way to do this: > >For classes that contain very simple data tables, I like to do >something like this: > >class Things(Object): >def __init__(self, x, y, z): >#assert that x, y, and z have the sa

Re: Checking length of each argument - seems like I'm fighting Python

2005-12-03 Thread Mike Meyer
"Brendan" <[EMAIL PROTECTED]> writes: > There must be an easy way to do this: Not necessarily. > For classes that contain very simple data tables, I like to do > something like this: > > class Things(Object): > def __init__(self, x, y, z): > #assert that x, y, and z have the same leng

Re: Checking length of each argument - seems like I'm fighting Python

2005-12-03 Thread Michael Spencer
Brendan wrote: ... > > class Things(Object): > def __init__(self, x, y, z): > #assert that x, y, and z have the same length > > But I can't figure out a _simple_ way to check the arguments have the > same length, since len(scalar) throws an exception. The only ways > around this I've

Re: Checking length of each argument - seems like I'm fighting Python

2005-12-03 Thread Alex Martelli
Sam Pointon <[EMAIL PROTECTED]> wrote: ... > So, assuming you want a Things object to break if either a) all three > arguments aren't sequences of the same length, or b) all three > arguments aren't a number (or string, or whatever), this should work: > > #Not tested. > class Things(object): >

Re: Checking length of each argument - seems like I'm fighting Python

2005-12-03 Thread Sam Pointon
It depends what you mean by 'scalar'. If you mean in the Perlish sense (ie, numbers, strings and references), then that's really the only way to do it in Python - there's no such thing as 'scalar context' or anything - a list is an object just as much as a number is. So, assuming you want a Things

Re: Checking length of each argument - seems like I'm fighting Python

2005-12-03 Thread Alex Martelli
Brendan <[EMAIL PROTECTED]> wrote: ... > def sLen(x): > """determines the number of items in x. > Returns 1 if x is a scalar. Returns 0 if x is None > """ > xt = numeric.array(x) > if xt == None: > return 0 > elif xt.rank == 0: > return 1 > else: >

Re: Checking length of each argument - seems like I'm fighting Python

2005-12-03 Thread Mike Erickson
* Brendan ([EMAIL PROTECTED]) wrote: [...] > Is there a simpler way to check that either all arguments are scalars, > or all are lists of the same length? Is this a poor way to structure > things? Your advice is appreciated Disclaimer: I am new to python, so this may be a bad solution. import t

Checking length of each argument - seems like I'm fighting Python

2005-12-03 Thread Brendan
There must be an easy way to do this: For classes that contain very simple data tables, I like to do something like this: class Things(Object): def __init__(self, x, y, z): #assert that x, y, and z have the same length But I can't figure out a _simple_ way to check the arguments have