Re: eval(repr(object)) hardly ever works

2006-09-13 Thread Hardcoded Software
Matthew Wilson wrote: > I understand that idea of an object's __repr__ method is to return a > string representation that can then be eval()'d back to life, but it > seems to me that it doesn't always work. > > For example it doesn't work for instances of the object class: > > In [478]: eval(repr(

Re: Test for number?

2006-09-04 Thread Hardcoded Software
Dr. Pastor wrote: > In the following code I would like to ascertain > that x has/is a number. What the simplest TEST should be? > (Could not find good example yet.) > --- > x=raw_input('\nType a number from 1 to 20') > if TEST : > Do_A > else: > Do_B > --- > Thanks for

Re: disgrating a list

2006-09-02 Thread Hardcoded Software
Tal Einat wrote: > Neil Cerutti wrote: > > On 2006-09-01, Tal Einat <[EMAIL PROTECTED]> wrote: > > > Tim Chase wrote: > > >> I'm not sure if '__iter__' is the right thing to be looking > > >> for, but it seems to work at least for lists, sets, > > >> dictionarys (via their keys), etc. I would use

Re: disgrating a list

2006-09-01 Thread Hardcoded Software
Tim Chase wrote: > >>> def flatten(x): > ... q = [] > ... for v in x: > ... if hasattr(v, '__iter__'): > ... q.extend(flatten(v)) > ... else: > ... q.append(v) > ... return q > ... Let's do some nitpicking on "pythonic" s