In this instance the trackback was somewhat unhelpful.<div>There problem was here:</div><div><br></div><div>           file = open(filename, 'r')<br><br></div><div>should be </div><div><br></div><div>           file = open(a, 'r')</div>
<div><br></div><div>args should be passed within the getopt riff</div><div><br><div class="gmail_quote">On Fri, Jul 17, 2009 at 11:08 AM, MRAB <span dir="ltr"><<a href="mailto:python@mrabarnett.plus.com">python@mrabarnett.plus.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5">LoD MoD wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I am having trouble extending my option parsing.<br>
Any help is appreciated:<br>
<br>
import sys<br>
import getopt<br>
import time<br>
<br>
def tail(file):<br>
    while 1:<br>
        where = file.tell()<br>
        line = file.readline()<br>
        if not line:<br>
            time.sleep(1)<br>
            file.seek(where)<br>
        else:<br>
            print line, # already has newline<br>
<br>
def main():<br>
<br>
    # parse command line options<br>
    try:<br>
        opts, args = getopt.getopt(sys.argv[1:], "hf:", ["help", "filename="])<br>
    except getopt.error, msg:<br>
        print msg<br>
        print "for help use --help"<br>
        sys.exit(2)<br>
    # process options<br>
    for o, a in opts:<br>
        if o in ("-h", "--help"):<br>
            print __doc__<br>
            sys.exit(0)<br>
        if o in ("-f", "--filename"):<br>
            print "Parsing F argument"<br>
            file = open(filename, 'r')<br>
            print file<br>
<br>
                        # process arguments<br>
    for arg in args:<br>
        process(arg) # process() is defined elsewhere<br>
<br>
if __name__ == "__main__":<br>
    main()<br>
<br>
Yields this error:<br>
<br>
localhost:src gsery$ python logTail.py  /var/log/system.log<br>
Traceback (most recent call last):<br>
  File "logTail.py", line 52, in <module><br>
    main()<br>
  File "logTail.py", line 49, in main<br>
    process(arg) # process() is defined elsewhere<br>
NameError: global name 'process' is not defined<br>
<br>
</blockquote></div></div>
The trackback tells you what's wrong: you haven't defined 'process'. The<br>
comment says it's defined elsewhere, but neither I nor Python can see<br>
it! :-)<br><font color="#888888">
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br></div>