Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 30th, 2007, 11:45 AM
Gilbert Fine
Guest
 
Posts: n/a
Default TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why?

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.

--
Gilbert

  #2  
Old July 30th, 2007, 11:55 AM
Steve Holden
Guest
 
Posts: n/a
Default Re: TypeError: unsupported operand type(s) for -: 'Decimal' and'Decimal'. Why?

Gilbert Fine wrote:
Quote:
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 -------------
  #3  
Old July 30th, 2007, 11:55 AM
Steve Holden
Guest
 
Posts: n/a
Default Re: TypeError: unsupported operand type(s) for -: 'Decimal' and'Decimal'. Why?

Gilbert Fine wrote:
Quote:
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 -------------

  #4  
Old July 30th, 2007, 12:05 PM
Marc 'BlackJack' Rintsch
Guest
 
Posts: n/a
Default Re: TypeError: unsupported operand type(s) for -: 'Decimal' and'Decimal'. Why?

On Mon, 30 Jul 2007 03:36:33 -0700, Gilbert Fine wrote:
Quote:
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 consolein <module>()

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

Ciao,
Marc 'BlackJack' Rintsch
  #5  
Old July 30th, 2007, 12:25 PM
Duncan Booth
Guest
 
Posts: n/a
Default Re: TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why?

Marc 'BlackJack' Rintsch <bj_666@gmx.netwrote:
Quote:
On Mon, 30 Jul 2007 03:36:33 -0700, Gilbert Fine wrote:
>
Quote:
>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:
>
<snip>

Or even just one Decimal type but not one which supports subtraction:
Quote:
Quote:
Quote:
>>class Decimal(object):
pass
Quote:
Quote:
Quote:
>>a = Decimal()
>>b = Decimal()
>>a-b
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:
Quote:
Quote:
Quote:
>>from decimal import Decimal
>>del Decimal.__sub__
>>Decimal()-Decimal()
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
Decimal()-Decimal()
TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'

  #6  
Old July 30th, 2007, 05:55 PM
Gilbert Fine
Guest
 
Posts: n/a
Default Re: TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why?

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.

--
Gilbert

On Jul 30, 7:20 pm, Duncan Booth <duncan.bo...@invalid.invalidwrote:
Quote:
Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
>
Quote:
On Mon, 30 Jul 2007 03:36:33 -0700, Gilbert Fine wrote:
>
Quote:
Quote:
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.
>
Quote:
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:
>
Quote:
Quote:
>class Decimal(object):
>
pass
>
Quote:
Quote:
>a = Decimal()
>b = Decimal()
>a-b
>
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:
>
Quote:
Quote:
>from decimal import Decimal
>del Decimal.__sub__
>Decimal()-Decimal()
>
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
Decimal()-Decimal()
TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'

  #7  
Old July 31st, 2007, 12:35 AM
Zentrader
Guest
 
Posts: n/a
Default Re: TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why?

from decimal import Decimal
Quote:
>
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).

  #8  
Old July 31st, 2007, 01:35 AM
John Machin
Guest
 
Posts: n/a
Default Re: TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why?

On Jul 31, 9:31 am, Zentrader <zentrad...@gmail.comwrote:
Quote:
Quote:
from decimal import Decimal
>
Quote:
In [21]: a = Decimal()
>
Quote:
In [22]: class Decimal(object):
....: pass
....:
>
Quote:
In [23]: b = Decimal()
>
Quote:
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.


  #9  
Old August 1st, 2007, 03:05 AM
Zentrader
Guest
 
Posts: n/a
Default Re: TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why?

In the utter absence of any clues from the OP, Marc was demonstrating
Quote:
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.

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles