473,382 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

Jul 30 '07 #1
8 9461
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 -------------
Jul 30 '07 #2
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 -------------

Jul 30 '07 #3
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 consolein <module>()

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

Ciao,
Marc 'BlackJack' Rintsch
Jul 30 '07 #4
Marc 'BlackJack' Rintsch <bj****@gmx.netwrote:
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'

Jul 30 '07 #5
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:
Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
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'

Jul 30 '07 #6
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).

Jul 30 '07 #7
On Jul 31, 9:31 am, Zentrader <zentrad...@gmail.comwrote:
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.
Jul 31 '07 #8
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.

Aug 1 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: DJ Craig | last post by:
I keep getting this error: Fatal error: Unsupported operand types in /usr/local/etc/httpd/htdocs/djtricities/kat/bpmchart/chart.php on line 58 I've looked for hours for some type of error, and...
3
by: Martin Koekenberg | last post by:
Hello, Ik get the following error when I install a new Python software package such as Zope or PIL. This is what I get whem I 'make' Zope : running build_ext Traceback (most recent call...
7
by: 5HH575-UAZWKVVP-7H2H48V3 | last post by:
(see end of message for example code) When an instance has a dynamically assigned instance method, deepcopy throws a TypeError with the message "TypeError: instancemethod expected at least 2...
3
by: Rakesh | last post by:
In my Python code fragment, I want to write a code fragment such that the minimum element of a tuple is subtracted from all the elements of a given tuple. When I execute the following python...
3
by: yaffa | last post by:
hey folks i get this error: Python interpreter error: unsupported operand type(s) for |: when i run this line of code: for incident in bs('tr', {'bgcolor' : '#eeeeee'} | {'bgcolor' :...
2
by: kath | last post by:
Hi, the following shows the contents of "datebook.xls" Date 8/9/2006 8/9/2006 8/9/2006 8/9/2006 8/9/2006
7
by: somenath | last post by:
Hi All, I am trying to undestand "Type Conversions" from K&R book.I am not able to understand the bellow mentioned text "Conversion rules are more complicated when unsigned operands are...
1
by: Todd O'Bryan | last post by:
This seems to have come up earlier... http://mail.python.org/pipermail/python-list/2007-July/451187.html but no resolution. We're seeing the same thing. We're using Django's DecimalField...
2
by: Jordan Harry | last post by:
I'm trying to write a simple program to calculate permutations. I created a file called "mod.py" and put the following in it: def factorial(n): a = n b = n while a>0 and b>1: n = (n)*(b-1)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.