0

I listed the follwoing question:

 http://stackoverflow.com/questions/11005335/python-sum-excel-file

I got great help on it, and now I am trying to convert another list in the same format and I am getting the following error using same code.

Traceback (most recent call last):
  File "C:/Python27/test2", line 37, in <module>
    checkList(name, symbol, amount)
  File "C:/Python27/test2", line 22, in checkList
    newObject = Object(name, symbol, int(amount)) #Create a new object with new name, produce, and amount
ValueError: invalid literal for int() with base 10: ''

I also was wondering if it is possible to convert the two excel files and then compare the two against each other to see differences?

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Trying_hard
  • 8,931
  • 29
  • 62
  • 85
  • clearly you are passing a bad string to int(). Just add a print of amount in your code before calling int(). Just before the error you'll see your non-int string – TJD Jun 19 '12 at 19:11

1 Answers1

2

You are seeing this error because at the line newObject = Object(name, symbol, int(amount)), the variable amount is an empty string.

There are two possibilities here, either that represents invalid data and you should not create a new Object instance to add to your list, or it is okay for amount to be '' and you just want to give it a default value (probably 0). Here is one way to do this:

newObject = Object(name, produce, int(amount) if amount else 0)
Andrew Clark
  • 202,379
  • 35
  • 273
  • 306