[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

at what complexity, a comparison fails ?

Stef Mientki

12/31/2007 10:46:00 AM

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 ?

thanks,
Stef Mientki


4 Answers

Marc 'BlackJack' Rintsch

12/31/2007 11:13:00 AM

0

On Mon, 31 Dec 2007 11:45:55 +0100, Stef Mientki wrote:

> 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.

Then you get the wrong impression.

> 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 ??

You are allowed and you do in the above code.

> And in general, how complex might a list be to make a valid comparison,
> or what are the rules ?

There are no rules about the complexity. Lists are compared element wise.
If the lists are of the same length and all elements at the corresponding
indexes compare equal, the lists are considered equal.

Ciao,
Marc 'BlackJack' Rintsch

Steven D'Aprano

12/31/2007 1:52:00 PM

0

On Mon, 31 Dec 2007 11:45:55 +0100, 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.

What do you mean "stopped working"?


> So it seems that comparing a too complex value isn't allowed. the
> variable was something like:
>
> A = [ <ndarray>, <ndarray>, ..., [<color>,<color>,...], [<float>,
> <float>, ... ] ]

Doesn't seem complex to me, and I daresay probably not to Python either
-- although a lot depends on what "ndarray" and "colour" are.


> 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 "crashes"? Explain please.



> 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 ?

As complicated as you like.



--
Steven

Zentrader

12/31/2007 5:15:00 PM

0

On Dec 31, 2:45 am, Stef Mientki <stef.mien...@gmail.com> wrote:
> So what I need was something like:
> if A != A_prev :
> ... do something
> A_prev = A
If A_prev is not declared prior to the if statement, you will get an
error when you try to compare the non-existing variable to A. This
code will work, at least for the snippet you provided.
A_prev=""
if A != A_prev :
... do something
A_prev = A
Please cut and paste the exact error message in the future.

Hans Nowak

12/31/2007 5:17:00 PM

0

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/....)

--Hans