On 2:59 PM, [email protected] wrote:
Hi,

I have code that works fine when I run it on Python 2.6.5, but I get an "invalid 
syntax" error in Python 2.4.3. I'm hoping you can help me fix it.

The line in question splits a chunk of semi-colon separated words into separate 
elements.

rgenre = re.split(r';', rf.info["genre"] if "genre" in rf.info else []

I get a syntax error at "if" in 2.4.3.

I tried doing the following but it doesn't work (I don't understand why).



if "genre" in rf.info:
           rgenre = re.split(r';', rf.info["genre"])
else:
           []


close.  The else clause should read:
                         rgenre = []
And I tried this, too:


if "genre" in rf.info:
           rgenre = re.split(r';', rf.info["genre"])
if "genre" not in rf.info:
           []

Both of these cause problems later on in the program, specifically 
"UnboundLocalError: local variable 'rgenre' referenced before assignment", 
about this line in the code (where each of these is one of the 30 possible genres):

rg1, rg2, rg3, rg4, rg5, rg6, rg7, rg8, rg9, rg10, rg11, rg12, rg13, rg14, rg15, rg16, 
rg17, rg18, rg19, rg20, rg21, rg22, rg23, rg24, rg25, rg26, rg27, rg28, rg29, rg30= 
rgenre + ["NA"]*(30-len(rgenre[:30]))

Thanks for any help--I gave a little extra information, but I'm hoping there's 
a simple rewrite of the first line I gave that'll work in Python 2.4.3.

Thanks,

Tyler

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to