On Mon, Oct 11, 2010 at 12:10 PM, <[email protected]> wrote:

>  <snip>
>
> rgenre = re.split(r';', rf.info["genre"] if "genre" in rf.info else []
>
> I get a syntax error at "if" in 2.4.3.
>

That's because you're using the ternary operator that was not available in
2.4: http://www.python.org/dev/peps/pep-0308/


>
> 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:
>           []
>
>
> 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):
>

The problem isn't with your logic expression - it's because on the else case
you never assign anything to rgenre, you simply state 'empty list' - not
'set rgenre to be an empty list'.

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

will work on all(?) versions of python - and 2.4 certainly.

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

Reply via email to