0

I am running a python script that opens a simple CSV file and pulls data from two columns, like:

ABC   6
DEF   7
GHI   12

Running my script with these values works as expected. But when I change the CSV file to include decimals, the script doesn't execute:

ABC   6.5
DEF   7
GHI   12.2

The output window instantly closes and terminates at this point in the code:

for row in csv_f:
    weight = long(row[1])
    print row[0], weight, weight * NAV / 100 

I tried replacing long with 'float' and that doesn't work either. Any ideas on why this is occurring and how to fix it?

JSmooth
  • 317
  • 1
  • 2
  • 13
  • what error are you getting? what is `NAV` set to? – R Nar Nov 06 '15 at 18:11
  • NAV is simply NAV = 100 at the top of the script. No error. Just the output terminal window opens then closes instantly. Never makes it to the line in the script asking for user input... – JSmooth Nov 06 '15 at 18:13
  • Maybe post a stack trace? – Chris Lawlor Nov 06 '15 at 18:21
  • 1
    `long('6.5')` -> `ValueError: invalid literal for long() with base 10: '6.5'`. You would see this error if you first opened a command-line window and ran your script with something like `python myscript.py` Tell us what error you get if you change it to `float(row[1])`. – martineau Nov 06 '15 at 18:21
  • I opened the command-line window to run the script. After changing it float(row[1]), it executed as expected. Thank you all very much for your help. – JSmooth Nov 06 '15 at 18:36

0 Answers0