How do I test if a variable that I declared in an inner block exists in the outer block?
<p>Given this sample Python code:</p>

<pre><code>for item in items:
    if somecondition(item):
        requireditem = item
        break

# use item
</code></pre>

<p>How can I know if I'm allowed to access <code>requireditem</code> after the loop? i.e. if <code>somecondition(item)</code> was <code>True</code> for some item in the list.</p>

<p>One solution might be:</p>

<pre><code>requireditem = None

for item in items:
    if somecondition(item):
        requireditem = item
        break

if requireditem != None:
    # do something
</code></pre>

<p>But I'm wondering what's the Pythonic way of doing this.</p>
