at what complexity, a comparison fails ?

Hans Nowak zephyrfalcon!NO_SPAM! at gmail.com
Mon Dec 31 12:17:27 EST 2007


Stef Mientki wrote:
> hello,
> 
> I had a program that worked perfectly well.
> In this program modules were dynamically added,
> just by putting the file in a predefined directory.
> 
> Now one of the interface mechanisms was to see if some parameter was 
> changed in a an instance,
> by comparing the value from the instance with its previous value
> 
> This went all well, untill I added a too complex variable,
> then the program stopped working, without generating exceptions.
> 
> So it seems that comparing a too complex value isn't allowed.
> the variable was something like:
> 
>  A = [ <ndarray>, <ndarray>, ..., [<color>,<color>,...], [<float>, 
> <float>, ... ] ]
> 
> So what I need was something like:
>    if  A != A_prev :
>        ... do something
>        A_prev = A
> 
> And this crashes, or at least it doesn't work but also doesn't generate 
> exceptions.
> It does seems to work, if A only contains 1 array.
> 
> Why am I not allowed to compare A and A_prev ??
> And in general, how complex might a list be to make a valid comparison,
> or what are the rules ?

I suspect that some of the objects in A have either undefined (or ill-defined) 
comparison methods, so that the overall list comparison does not do what you 
expect.  I'm not sure what ndarray and color are, but check their comparison 
methods (you know, __cmp__, __lt__, __eq__, etc).  (If that isn't clear, please 
see http://effbot.org/pyref/__lt__.htm.)

--Hans



More information about the Python-list mailing list