Use function outside method declaration : <p>I have a function <code>get_user_agent()</code>:</p>

<pre><code>def get_user_agent():
    valid_user_agents = []
    db = pymysql.connect(host='localhost', user='root',passwd='password',db='garbagedb')
    cursor = db.cursor()
    try:
        with db.cursor() as cursor:
            useragent_query = "SELECT `ua` FROM `useragent`"
            cursor.execute(useragent_query)
            useragent_value = cursor.fetchall()
            valid_user_agents.append(useragent_value)
        db.close()
    except:
        print("error SELECTing useragent_value")
    return valid_user_agents     

db = pymysql.connect(host='localhost', user='root',passwd='password',db='garbagedb')
cursor = db.cursor()

get_user_agent() # function invoked
</code></pre>

<p>Then to try to use the <code>list</code> <code>valid_user_agents</code> - This <strong>does not</strong> work:</p>

<pre><code>for ua in valid_user_agents:
    print("do something?")
</code></pre>

<p>But then I cant use in a <code>for</code> loop, what am I doing wrong?</p>
