Hi, Don't hate me cuz I am a NUB.

This may be very basic but I am more basic when it comes to python

I simply need to add some variables together some come from a database and some are calculated. but I am getting a very frustrating error

TypeError: unsupported operand type(s) for +: 'Decimal' and 'float'

The section of code corresponding to this is

total_cost = sum_results['list_price'] + salestax + shipping_cost + rush_cost

I actually have this code around this where I am print the variables I don't know if this will help

here is the code and the output

print sum_results['list_price']
	print salestax
	print shipping_cost
	print rush_cost
	
		
	total_cost = sum_results['list_price'] + salestax + shipping_cost + rush_cost

OUTPUT

244.80
0.0
6.95
10.00
Traceback (most recent call last):
  File "new_export_csv.py", line 403, in ?
    total_cost = sum_results['list_price'] + salestax + shipping_cost + rush_cost
TypeError: unsupported operand type(s) for +: 'Decimal' and 'float'

I followed the rest of the coding by example as I am very new to PYTHON

Here is a larger section of code so you can see what is going on

In a nutshell I have a
sub-total
I calculate a sales tax of 5% if the the order comes from Maine 'ME'
I have shipping charge
I have a rush shipping charge

and I want to add them together

here is the relevent code

if(row['use_billing_address'] == 1):
		if(row['billing_state'] == 'ME'):
			salestax = sum_results['list_price'] * .05
		else:
			salestax = 0.0
	else:
		if(row['shipping_email'] == 'ME'):
			salestax = sum_results['list_price'] * .05
		else:
			salestax = 0.0		
	
	str_format +=  '%(salestax)9s'
	str_data['salestax'] = salestax
	
	
	
	print sum_results['list_price']
	print salestax
	print shipping_cost
	print rush_cost
	
		
	total_cost = sum_results['list_price'] + salestax + shipping_cost + rush_cost
	total_shipping_cost = shipping_cost + rush_cost
	

	
	#continued
	str_format +=  '%(continued)1s'
	str_data['continued'] = 'N'

A quick reponse would be greatly appreciated as this code is supposed to go live tonight.

here is a list of the import I do

import MySQLdb
import sys
from datetime import datetime, timedelta
import ftplib

I know this is probably confusing and I am sorry for that but your help is greatly appreciated

Jeff

Assuming that sum_results is a dictionary that contains numbers of decimal class, you can use

total_cost = float(sum_results['list_price']) + salestax + shipping_cost + rush_cost

If this doesn't work, then print the type for each variable
print type(sum_results) etc.
You can check the docs for the decimal class at python.org if you want to know more about it.

This question has already been answered. Start a new discussion instead.