[Tutor] Extract strings from a text file
wesley chun
wescpy at gmail.com
Fri Feb 27 08:59:44 CET 2009
> There is a text file that looks like this:
>
> text text text <ID>Joseph</text text text>
> text text text text text text text text text text text
> text text text text text text text text text text text
> text text text text text text text text text text text
> text text text text text text text text text text text
> text text text text text text text text text text text
> text text text text text text text text text text text
> text text text text text text text text text text text
> text text text <Full name> Joseph Smith</text text text>
> text text text <Rights> 1</text text text>
> text text text <LDAP> 0</text text text>
>
> What I am trying to do is:
>
> 1. I need to extract the name and the full name from this text file. For
> example: ( ID is Joseph & Full name is Joseph Smith).
in addition to denis' suggestion of using regular expressions, you can
also look at the xml.etree module and have ElementTree parse them into
tags for you, so all you have to do is ask for the ID and "Full name"
tags to get your data.
good luck!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
http://corepython.com
wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
More information about the Tutor
mailing list