[Tutor] Tutor Digest, Vol 37, Issue 63
alan.gauld at btinternet.com
Sun Mar 25 17:27:29 CEST 2007
"Jay Mutter III" <jmutter at uakron.edu> wrote
> The following is what I put in (interactively) and what I got out.
> >>> ss = open('inp.txt')
> >>> s = ss.read()
> >>> s.replace('p. ','\n')
> 'Barnett, John B., assignor of one-half to R. N. Tutt, Kansas City,
> Mo. Automatic display-sign.\xc2\xa0 \xc2\xa0 No. 1,330 411-Apr. 13 ;
> v. 273 ;\xc2\xa0\n\n193. Barnett,\xc2\xa0 John\xc2\xa0 II..\xc2\xa0
Try using print s.replace()
You are getting caught with the difference between repr() and str()
Python uses repr when evaluating an expression at the >>> prompt
but uses str() when using print. Try:
>>> print 'here are lines\nof text'
>>> repr ('here are lines\nof text')
> I though about treating it as a list of lines, stripping carriage
> returns on the basis of some criteria but i have never gotten rstrip
> to work
Strange, what happens? rstrip() is pretty simple!
More information about the Tutor