TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why?

G

Gilbert Fine

This is a very strange exception raised from somewhere in our program.
I have no idea how this happen. And don't know how to reproduce. It
just occurs from time to time.

Can anyone give me some suggestion to fix this?

Thanks.
 
S

Steve Holden

Gilbert said:
This is a very strange exception raised from somewhere in our program.
I have no idea how this happen. And don't know how to reproduce. It
just occurs from time to time.

Can anyone give me some suggestion to fix this?
If it's raised from "somewhere in your program" the first this to do is
disable the except clause that is apparently stopping you from getting a
full traceback, then post that traceback with an appropriate code snippet.

People on this list are good at guessing, but it's better to give then
some hard information to work with.

Otherwise you are calling the shop (garage?) and saying "My car doesn't
work, can you tell me how to fix it, please?"

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
 
S

Steve Holden

Gilbert said:
This is a very strange exception raised from somewhere in our program.
I have no idea how this happen. And don't know how to reproduce. It
just occurs from time to time.

Can anyone give me some suggestion to fix this?
If it's raised from "somewhere in your program" the first this to do is
disable the except clause that is apparently stopping you from getting a
full traceback, then post that traceback with an appropriate code snippet.

People on this list are good at guessing, but it's better to give then
some hard information to work with.

Otherwise you are calling the shop (garage?) and saying "My car doesn't
work, can you tell me how to fix it, please?"

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
 
M

Marc 'BlackJack' Rintsch

This is a very strange exception raised from somewhere in our program.
I have no idea how this happen. And don't know how to reproduce. It
just occurs from time to time.

Maybe different `Decimal`\s? Here's how to reproduce such a traceback:

In [20]: from decimal import Decimal

In [21]: a = Decimal()

In [22]: class Decimal(object):
....: pass
....:

In [23]: b = Decimal()

In [24]: a - b
<type 'exceptions.TypeError'> Traceback (most recent call last)

/home/bj/<ipython console> in <module>()

<type 'exceptions.TypeError'>: unsupported operand type(s) for -: 'Decimal' and 'Decimal'

Ciao,
Marc 'BlackJack' Rintsch
 
D

Duncan Booth

Marc 'BlackJack' Rintsch said:
Maybe different `Decimal`\s? Here's how to reproduce such a
traceback:
<snip>

Or even just one Decimal type but not one which supports subtraction:
pass

Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
a-b
TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'

Another option of course is that Decimal() did support substraction but
someone deleted it:

Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
Decimal()-Decimal()
TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'
 
G

Gilbert Fine

Thanks. I think I have some direction to do logging, to get more
information about this problem.

It seems that I don't get used to dynamic language yet.
 
Z

Zentrader

from decimal import Decimal
In [21]: a = Decimal()

In [22]: class Decimal(object):
....: pass
....:

In [23]: b = Decimal()

In [24]: a - b

Perhaps I don't understand what you are doing here, but on line 22 you
overload Decimal. If you just have
a = Decimal()
b = Decimal()
print a-b yields 0. decimal.Decimal() can be subtracted from
decimal.Decimal(). decimal.Decimal() can not be subtracted from class
Decimal(object). I would assume that they are different types. Using
the original code, print type(a), type(b).
 
J

John Machin

from decimal import Decimal
In [21]: a = Decimal()
In [22]: class Decimal(object):
....: pass
....:
In [23]: b = Decimal()
In [24]: a - b

Perhaps I don't understand what you are doing here, but on line 22 you
overload Decimal.

In the utter absence of any clues from the OP, Marc was demonstrating
one possible way that the puzzling [Can't subtract one Decimal
instance from another???] error message could have been caused.
 
Z

Zentrader

In the utter absence of any clues from the OP, Marc was demonstrating
one possible way that the puzzling [Can't subtract one Decimal
instance from another???] error message could have been caused.

Ah yes. Until this is no longer true, "In the utter absence of any
clues from the OP", we can do no more. My appologies to Marc for
misinterpretation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top