[Tutor] newbie: Reading text file
Kent Johnson
kent37 at tds.net
Fri Jun 1 14:04:46 CEST 2007
Grant Hagstrom wrote:
> Thanks for the links. I'll check them out. You don't happen to have any
> parsing tutorials bookmarked somewhere do you? I'm already exploring
> http://gnosis.cx/TPiP/. It's pretty heavy though.
For general text processing, you might want to browse the Text section
of the Python Cookbook, either the printed version or online:
http://aspn.activestate.com/ASPN/Cookbook/Python?kwd=Text
Many text processing problems can be solved with the string methods or
regular expressions and a simple state machine.
http://docs.python.org/lib/string-methods.html
http://www.amk.ca/python/howto/regex/
If the data structure is recursive or the number of possible states is
more than a handful, you may want to use a parsing package. I recommend
looking at at pyparsing or PLY. I have found both of them to be well
documented and pretty easy to use. Links to these and many other Python
parser packages here:
http://www.nedbatchelder.com/text/python-parsers.html
Kent
PS Please use reply all to reply to the list.
More information about the Tutor
mailing list