[Tutor] parsing text

Alan Gauld alan.gauld at btinternet.com
Sun Mar 25 01:00:29 CET 2007


"Jay Mutter III" <jmutter at uakron.edu> wrote

> i have the following text:
>
> Barnett, John B., assignor of one-half to R. N. Tutt, Kansas City,
> Mo.    Automatic display-sign.    No. 1,330 411-Apr. 13 ; v. 273 ; 
> p.
> 193.
> Barnett,  John  II..  Tettenhall,  England.     Seat  of
> motorcars.    No. 1.353,708; Sept. 21 ; v. 278; p. 487. Barnett, 
> Otto
> R.    (See Scott, John M., assignor.)
>
> 1.) when i do readlines and create a list and then print the list it
> adds a blank line between every line of text

I suspect that's because you are reading a newline character
from the file and print adds a newline of its own. You need to
use rstrip() to take out the newline from the file.

> 2.)in the second line after p.487 there is the beginning of a new
> line of data only it isn't on a newline.

I'm not quite sure what you mean here.
It would be helpful if you can show us the problematic output
as well as the input. Also to send us the actual code fragments
that are causing the damage.

> i tried string.replace(s,'p.','\n') in an attempt to put a CR in but
> it just put the characters\n in the string.

Dont use the string module functions. Use the string methods,
so it becomes:

s.replace('p.', '\n')

However that doesn't explain why you are getting the literal
characters! Can you send us the actual code you are using?
And the output showing the error?

HTH,

Alan G. 




More information about the Tutor mailing list