On Tue, 14 Sep 2010 01:58:07 pm aenea...@priest.com wrote:
> if len(rgenre)>0:
> if len(rgenre)>2:
> rg1=rgenre[0]
> rg2=rgenre[1]
> rg3=rgenre[2]
> elif len(rgenre)==2:
> rg1=rgenre[0]
> rg2=rgenre[1]
>
On Tue, 14 Sep 2010 02:08:43 pm Vince Spicer wrote:
> Hey Tyler you can simplify this with a onliner.
>
> rg1, rg2, rg3 = rgenre + ["NA"]*(3-len(rgenre[:3]))
There's no real need to calculate the exact length that you want:
rg1, rg2, rg3 = (rgenre + ["NA"]*3)[:3]
For small numbers of items -- a
On Tue, Sep 14, 2010 at 2:46 PM, wrote:
> rgenre = re.split(r';', rf.info["genre"])
> KeyError: 'genre'
Use something like this:
if "genre" in rf.info:
rgenre = re.split(..., ...)
else:
# ... no genre
cheers
James
--
-- James Mills
--
-- "Problems are solved by method"
on't choke if you don't find any rgenres
> because rf.info["genre"] was empty". But maybe I need to define the "None"
> condition earlier?
>
> Basically a text file has this structure:
>
> High Noon
> Drama;Western # But this tag doesn't
A great flick
blah blah blah
# etc
# next review--all about the movie featured in the info tags
-----Original Message-
From: Vince Spicer
To: aenea...@priest.com
Cc: tutor@python.org
Sent: Mon, Sep 13, 2010 9:08 pm
Subject: Re: [Tutor] If/elif/else when a list is empty
On Mon, Sep 13, 201
On Tue, Sep 14, 2010 at 1:58 PM, wrote:
> rgenre = re.split(r';', rf.info["genre"]) # When movies have genre
First question. Why are you not using an XML parser (it looks like
your IMDB data files _are_ XML). e.g: elementree (in the standard
library).
> else len(rgenre)<1: # I was hoping thi
On Mon, Sep 13, 2010 at 9:58 PM, wrote:
> Hi,
>
> I'm parsing IMDB movie reviews (each movie is in its own text file). In my
> script, I'm trying to extract genre information. Movies have up to three
> categories of genres--but not all have a "genre" tag and that fact is making
> my script abort
Hi,
I'm parsing IMDB movie reviews (each movie is in its own text file). In my
script, I'm trying to extract genre information. Movies have up to three
categories of genres--but not all have a "genre" tag and that fact is making my
script abort whenever it encounters a movie text file that doe