Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:07:23+00:00 2026-06-14T20:07:23+00:00

Have two scripts that give very different results. First using csv.reader and it works

  • 0

Have two scripts that give very different results. First using csv.reader and it works fine, then csv.dictreader which has given me problems. Both scripts use the same set of data, only difference between the two files is that the one dictreader uses has headers.

import csv

inv = csv.reader(open('inv.txt', 'rU'), dialect='excel', delimiter="\t")

for PART_CODE,MODEL_NUMBER,PRODUCT_NAME,COLOR,TOTAL_ONHAND,TOTAL_ON_ORDER,TOTAL_SALES,SALES_YEAR_TO_DATE,SALES_LASTYEAR_TO_DATE,\
TOTAL_NUMBER_OF_QTYsSOLD,TOTAL_PURCHASES,PURCHASES_YEAR_TO_DATE,PURCHASES_LASTYEAR_TO_DATE,TOTAL_NUMBER_OF_QTYpurchased,DATE_LAST_SOLD,DATE_FIRST_SOLD in inv:
    if int(TOTAL_ON_ORDER) >= 1:
        print ('%-20s %-100s OnHand: %-4s OnOrder: %-4s') % (MODEL_NUMBER,PRODUCT_NAME,TOTAL_ONHAND,TOTAL_ON_ORDER)

The above works just fine, it’ll parse through the 20,000 plus items with no error. Now if I choose to use dictreader as in the below, the script will run into problems after a while…

import csv

inv = csv.DictReader(open('ireport.txt', 'rU'), dialect='excel', delimiter="\t")

for row in inv:
    if int(row['TOTAL_ON_ORDER']) >= 1:
        print ('%-20s %-100s OnHand: %-4s OnOrder: %-4s') % (row['MODEL_NUMBER'],row['PRODUCT_NAME'],row['TOTAL_ONHAND'],row['TOTAL_ON_ORDER'])

Prints out about 100 or so, then fails and reports this error:

if int(row['TOTAL_ON_ORDER']) >= 1:

ValueError: invalid literal for int() with base 10: 'False'

Puzzles me as both scripts use the same data (other than the reader one has no header row and the dictreader one does) one works flawlessly, the other complains. Any clues?

Snippet of inv.txt:

61965901576 383964  Sandisk 128MB 3.3V Smartmedia Card      0   0   0   0   0   0   0   0   0   0   00/00/00    00/00/00
61965901521 348236  Sandisk 128MB Compactflash Card     0   0   54.26   0   0   1   0   0   0   0   01/09/02    01/09/02
61965902011 SDCZ2-1024-A10  Sandisk 1GB Cruzer Mini USB Flash Drive     0   0   0   0   0   0   0   0   0   0   00/00/00    00/00/00
61965901571 266796  Sandisk 256MB CompactFlash Disk     0   0   678.22  0   0   5   0   0   0   0   06/27/02    03/08/02
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:07:24+00:00Added an answer on June 14, 2026 at 8:07 pm

    It looks like it’s reading something as a Boolean into an integer (which it’s not happy with) in the DictReader function, whereas in the reader function it is not getting that cast as such.

    Try this:

    import csv
    
    inv = csv.DictReader(open('ireport.txt', 'rU'), dialect='excel', delimiter="\t")
    
    for row in inv:
        try:
          if int(row['TOTAL_ON_ORDER']) >= 1:
              print ('%-20s %-100s OnHand: %-4s OnOrder: %-4s') % (row['MODEL_NUMBER'],row['PRODUCT_NAME'],row['TOTAL_ONHAND'],row['TOTAL_ON_ORDER'])
        except Exception as Err:
          print row['TOTAL_ON_ORDER'],Err
          break #if you want to end the function)
    

    This will show you what line it’s choking on, and if you remove the break should chug through it.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two scripts that are called in one program, the first script creates
Setup: I have two trees of scripts that run on Oracle 11g - one
I have two repos that I want to have different info associated with it.
I have a script that runs every two minutes for a Tweet-getter application. In
I have a script that generates two lines as output each time. I'm really
I have an MSBuild script that uses NUnit to run tests in two assemblies.
I currently have a ajax script that dynamically builds two select boxes enabled with
My script is here : jsfiddle i have two attributes in my form that
I have two scripts running on the same page, one is the jQuery.hSlides.js script
I have written two scripts where one script calls subprocess.Popen to run a terminal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.