473,623 Members | 3,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9516
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.Typ eError' Traceback (most recent call last)

/home/bj/<ipython consolein <module>()

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

Ciao,
Marc 'BlackJack' Rintsch
Jul 30 '07 #4
Marc 'BlackJack' Rintsch <bj****@gmx.net 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#1 5>", 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...@i nvalid.invalidw rote:
Marc 'BlackJack' Rintsch <bj_...@gmx.net 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#1 5>", 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...@gma il.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
misinterpretati on.

Aug 1 '07 #9

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

Similar topics

6
34656
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 tried lots of different things, but I can't get it to work. I did a google search for "unsupported operand types" and for most of the people getting this error, it was something to do with the version of PHP that they were running, but I can't...
3
11553
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 last): File "/usr/local/zope/Zope-2.7.2-0/setup.py", line 1091, in ?
7
3963
by: ‘5ÛHH575-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 arguments, got 0". Tested with Python 2.3.4 on OpenBSD and Python 2.4 on Win98; same results. Is this a bug in deepcopy, how I dynamically assign the instance method or something else? (See example code for how I did it.) If you're curious as...
3
9681
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 script I get the following interpreter error.
3
3156
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' : 'white'} ): any idea what i'm doing wrong here?
2
13980
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
5038
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 involved. The problem is that comparisons between signed and unsigned values are machine- dependent, because they depend on the sizes of the various integer types. For example, suppose that int is 16 bits
1
1655
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 type and when we try to add or subtract values--which should be decimal.Decimal objects--we occasionally get an error about the operator not being supported. It doesn't always happen and we can't
2
8429
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) b = b-1 def perm(n, r):
0
8221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8162
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8603
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7134
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5560
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4067
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2593
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.