UnboundLocalError: local variable 'file' referenced before assignment
<p>Guyz,am running into following error with the belwo code,where is ti going wrong?
any cleanup suggestions also accepted</p>

<pre><code>    for line in file(timedir + "/change_authors.txt"):
UnboundLocalError: local variable 'file' referenced before assignment
</code></pre>

<p>Code below:</p>

<pre><code>    import os,datetime
    import subprocess
    from subprocess import check_call,Popen, PIPE
    from shutil import copyfile,copy

def main ():
    #check_call("ssh -p 29418 review-droid.comp.com change query --commit-message status:open project:platform/vendor/qcom-proprietary/radio branch:master | grep -Po '(?&lt;=(email|umber): )\S+' | xargs -n2")
    global timedir
    change=147441
    timedir=datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
    #changeauthors = dict((int(x.split('/')[3]), x) for line in file(timedir + "/change_authors.txt"))
    for line in file(timedir + "/change_authors.txt"):
        changeauthors = dict(line.split()[0], line.split()[1]) 
    print changeauthors[change]
    try:
        os.makedirs(timedir)
    except OSError, e:
        if e.errno != 17:
            raise # This was not a "directory exist" error..
    with open(timedir + "/change_authors.txt", "wb") as file:
        check_call("ssh -p 29418 review-droid.comp.com "
            "change query --commit-message "
            "status:open project:platform/vendor/qcom-proprietary/radio branch:master |"
            "grep -Po '(?&lt;=(email|umber): )\S+' |"
            "xargs -n2",
                shell=True,   # need shell due to the pipes
                stdout=file)  # redirect to a file

if __name__ == '__main__':
    main()
</code></pre>
