Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why?

Reply
Thread Tools

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

 
 
Gilbert Fine
Guest
Posts: n/a
 
      07-30-2007
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

 
Reply With Quote
 
 
 
 
Steve Holden
Guest
Posts: n/a
 
      07-30-2007
Gilbert Fine wrote:
> 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 -------------
 
Reply With Quote
 
 
 
 
Steve Holden
Guest
Posts: n/a
 
      07-30-2007
Gilbert Fine wrote:
> 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 -------------

 
Reply With Quote
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      07-30-2007
On Mon, 30 Jul 2007 03:36:33 -0700, Gilbert Fine wrote:

> 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
 
Reply With Quote
 
Duncan Booth
Guest
Posts: n/a
 
      07-30-2007
Marc 'BlackJack' Rintsch <(E-Mail Removed)> wrote:

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

>>> class Decimal(object):

pass

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

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

 
Reply With Quote
 
Gilbert Fine
Guest
Posts: n/a
 
      07-30-2007
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 <(E-Mail Removed)> wrote:
> Marc 'BlackJack' Rintsch <(E-Mail Removed)> wrote:
>
> > On Mon, 30 Jul 2007 03:36:33 -0700, Gilbert Fine wrote:

>
> >> 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:
>
> >>> class Decimal(object):

>
> pass
>
> >>> 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:
>
> >>> 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'



 
Reply With Quote
 
Zentrader
Guest
Posts: n/a
 
      07-30-2007
> 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).

 
Reply With Quote
 
John Machin
Guest
Posts: n/a
 
      07-31-2007
On Jul 31, 9:31 am, Zentrader <(E-Mail Removed)> wrote:
> > 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.


 
Reply With Quote
 
Zentrader
Guest
Posts: n/a
 
      08-01-2007
> 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.

 
Reply With Quote
 
 
 
Reply

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unsupported operand type(s) for ^: 'float' and 'float' Florian Lindner Python 1 06-15-2007 01:39 PM
Re: TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple' Jay Parlar Python 0 03-17-2006 02:58 AM
Python interpreter error: unsupported operand type(s) for -: 'tuple' and 'int' Rakesh Python 3 03-30-2005 02:36 PM
Re: TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' Brett C. Python 2 08-30-2004 10:25 PM
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' Martin Koekenberg Python 3 08-26-2004 12:04 PM



Advertisments