Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'delimited': 0.09; 'literal': 0.09; 'valueerror:': 0.09; 'subject:How': 0.10; 'csv': 0.16; 'delimiter': 0.16; 'denote': 0.16; 'fine.': 0.16; 'integers.': 0.16; 'separated': 0.16; 'tab': 0.16; 'thanks,': 0.17; 'module': 0.19; 'everyone,': 0.19; 'import': 0.22; 'print': 0.22; 'file.': 0.24; "i've": 0.25; 'this:': 0.26; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'file': 0.32; '(most': 0.33; 'received:google.com': 0.35; '14,': 0.36; 'dates': 0.36; 'doing': 0.36; 'subject:?': 0.36; 'skip:o 20': 0.38; 'to:addr :python-list': 0.38; 'recent': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'needing': 0.65; 'invalid': 0.68; 'subject:this': 0.83; '10:': 0.84; 'cast': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=00Hir8t/sGt8gAWvKzoNjdxt153gmgsSMg1ocKkN8RI=; b=kugDaCzlCiRNf/b6BXGwGJ2BRwWNbdf6/AvUj/SnmkgVyo44jPA7XLvy+IPlFzo1zU ZYeuqC/COFLvhwQpnmwbpRdtfhhA/89D5H+AnP8GUVjuMEEheDdlaXKRhIXal4rVtRII yAkie929xVF9yFYjJ0N9TG+Gk4FGzjrx+s7SNq+zAul+6AGhgJqodPkfOBviUMK8v3nJ 8mPn6gZcReQP+/+GuNF6jif2gjhjjgRL4yu/j6aSH1WXelQ1LbCIzgon5M3ZtsL4GLyn RsdmuqQafmoMS0ePTwpwlKvSFKyuW99y5EiCxX4g32hxa8rMfNJKTry9Qd2YA0v68K0O gMqg== X-Received: by 10.236.99.99 with SMTP id w63mr2935421yhf.52.1396756363462; Sat, 05 Apr 2014 20:52:43 -0700 (PDT) MIME-Version: 1.0 From: Anthony Papillion Date: Sat, 5 Apr 2014 22:52:23 -0500 Subject: How can I parse this correctly? To: python-list@python.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396756706 news.xs4all.nl 2882 [2001:888:2000:d::a6]:41100 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69737 Hello Everyone, I'm working with historical earthquake data and I have a tab delimited file. I'm using the csv module with the \t delimiter to denote it's tab separated and it's working fine. I've set things up loike this: import csv f = open('earthquakes.tsv') r = csv.DictReader(f, delimiter='\t') for row in r: print row['YEAR'] This works fine. But, I am needing to do date addition/subtraction using datetime and so I need these dates as integers. When I try to cast them like this: print int(row['YEAR']) I am told by the interpreter: Traceback (most recent call last): File "analyze.py", line 14, in print int(row['MONTH']) ValueError: invalid literal for int() with base 10: '' What am I doing wrong? Am I not understanding HOW to cast? Thanks, Anthony