<div class="gmail_quote">On Mon, Oct 11, 2010 at 12:10 PM, <span dir="ltr"><<a href="mailto:aeneas24@priest.com">aeneas24@priest.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<font color="black" size="2" face="arial">
<div><font face="Arial, Helvetica, sans-serif"></font><snip></div>
<div> </div>
<div>rgenre = re.split(r';', <a href="http://rf.info" target="_blank">rf.info</a>["genre"] if "genre" in <a href="http://rf.info" target="_blank">rf.info</a> else []</div>
<div> </div>
<div>I get a syntax error at "if" in 2.4.3.</div></font></blockquote><div><br></div><div>That's because you're using the ternary operator that was not available in 2.4: <a href="http://www.python.org/dev/peps/pep-0308/">http://www.python.org/dev/peps/pep-0308/</a></div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><font color="black" size="2" face="arial"><div> </div>
<div> </div>
<div>I tried doing the following but it doesn't work (I don't understand why). </div>
<blockquote style="margin-right:0px" dir="ltr"><div>if "genre" in <a href="http://rf.info" target="_blank">rf.info</a>:<br>
rgenre = re.split(r';', <a href="http://rf.info" target="_blank">rf.info</a>["genre"])<br>
else:<br>
[]</div>
<div> </div>
</blockquote>
<div>And I tried this, too: </div>
<div> </div>
<blockquote style="margin-right:0px" dir="ltr">
<div>if "genre" in <a href="http://rf.info" target="_blank">rf.info</a>:<br>
rgenre = re.split(r';', <a href="http://rf.info" target="_blank">rf.info</a>["genre"])<br>
if "genre" not in <a href="http://rf.info" target="_blank">rf.info</a>:<br>
[]</div>
</blockquote>
<div dir="ltr">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):</div>
</font></blockquote><div><br></div><div>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'.</div>
<div><br></div><div>if 'genre' in <a href="http://rf.info">rf.info</a>:</div><div> rgenre = re.split(r';', <a href="http://rf.info">rf.info</a>['genre'])</div><div>else:</div><div> rgenre = []</div>
<div><br></div><div>will work on all(?) versions of python - and 2.4 certainly.</div><div><br></div><div>HTH,</div><div>Wayne</div></div>