Python's BNF

Steve Holden steve at
Thu Feb 28 21:03:30 CET 2008

MartinRinehart at wrote:
> Implemented all your suggestions, with two exceptions.
> Changed file read to readlines(), but not open(...).readlines(). I
> love to say file.close(). Gives me a feeling of security. (We could
> discuss RAM waste v. I/O speed but this input file is just 10KB, so
> neither matters.)
> Removed one of the three globals, but left the other two. Couldn't see
> any real advantage to passing poor 'ofile' from hand to hand
> (writeHTML() to writeBody() to writeEntries() ...) as opposed to
> letting him rest easy in his chair, doing a little writing when
> called.
Note that if you call the parameter to the function "ofile" as well, you 
don't need to change *any* other code to get correct behavior.

But in general terms it's a practice you should adopt as early as 
possible, because it gets very tedious very quickly to have to trace the 
use of global variables in programs of any size.

Avoiding the use of globals is just good program hygiene.

Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC    

More information about the Python-list mailing list