[Tutor] Extract strings from a text file

Mohamed Hassan linuxlover00 at gmail.com
Fri Feb 27 06:53:43 CET 2009


Hi all,

I am new to Python and still trying to figure out some things. Here is the
situation:

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>


This text file is very long, however all the entries in it looks the same at
the above.

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).


- I am thinking I need to write something that will check the whole text
file line by line which I have done already.
- Now what I am trying to figure out is : How can I write a function that
will check to see if the line contains the word ID between < > then copy the
letter after > until > and dump it to a text file.

Can somebody help please. I know this might soudn easy for some people, but
again I am new to Python and still figuring out things.

Thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090226/2dddc721/attachment.htm>


More information about the Tutor mailing list