NameError while handling command line arguments
<p>I was trying out a few python test scripts with sqlite3.</p>

<p>Here is the script that I wrote</p>

<pre><code>#!/usr/bin/env python

from sqlite3 import dbapi2 as sqlite
from sys import argv,exit

db_name = "filenames.db"

def define_db():
    try:
        conn = sqlite.connect(db_name)
    except IOError as e:
        print "problem while creating/connecting the db:",e.args[0]
        exit(1)

    return conn

def write_db(conn,cursor,fni):
    conn.execute("CREATE TABLE IF NOT EXISTS file (filenames TEXT UNIQUE)")
    query = "INSERT OR REPLACE INTO file VALUES($filenames)"

    cursor.execute(query,[fni])
    cursor.close()  
    conn.commit()
    conn.close()
    print fni,"should now be in the db" 
    exit(0)

if __name__ == "__main__":
    if len(argv) == 2:
        etag = argv[1]
    else:
        print "no argument given - stopping now"
        exit(1)

    conn = define_db()
    cursor = conn.cursor()
    write_db(conn,cursor,fni)
</code></pre>

<p>I keep getting this error and was not able to solve it.</p>

<pre><code>Traceback (most recent call last):
  File "blah.py", line 37, in &lt;module&gt;
    write_db(conn,cursor,fni)
NameError: name 'fni' is not defined
</code></pre>

<p>Any idea what the problem is. </p>

<p>At this moment I use python 2.7.3</p>
