En Wed, 27 Feb 2008 15:23:01 -0200, <[EMAIL PROTECTED]> escribi�: > I spent too long Googling for Python's BNF. Eventually found it at > Python.org, but only by accident. > > There's a link to the program, top-right of page. If anyone wants to > look at this no-longer-quite-newbie's code and give a constructive > critique, I'd be grateful.
- Try not to use so many globals. By example: ofile = open( '\decaf\python-parse-bnf.html', 'w' ) writeHTML() ofile.close() I'd pass ofile as an argument to writeHTML - along with *what* to write. - The "\" is an escape character. Use either '\\decaf\\python-parse-bnf.html' or r'\decaf\python-parse-bnf.html' or '/decaf/python-parse-bnf.html' (the later works more-or-less with all internal Windows functions, but usually not from the command line) - Instead of: while i < len( bnf ): s = bnf[i] use for s in bnf: That is, iterate over the list elements (what you want), not over the indexes. In case you want also the index, use: for i,item in enumerate(items): - The fileRead function could be written simply as: return open(...).readlines(); but you don't have to keep all the contents in memory at once, so forget about fileRead and make prepareDict iterate over the file, line by line; that's easy: for s in open(...): if startDef:... - This whole block: plist = [] for pname in productions: plist.append( pname ) plist.sort() is the same as: plist = sorted(productions) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list