[Tutor] String Replace.....

Sheila King sheila@thinkspot.net
Sun, 28 Jan 2001 13:31:01 -0800


I'm only a Python newbie, myself, but I've done a fair number of scripts with
strings in them, and I've never used '\012' in my code, only '\n'.

Maybe, try replacing the "\012" in your code with "\n"  ???

Well, I figured it was worth a try?

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/

On Sun, 28 Jan 2001 21:17:07 -0000, "Budgester" <budgester@budgester.com>
wrote about [Tutor] String Replace.....:

:## Turn Text into HTML
:
:    def htmlize(self):
:        viewdiary = open("c:\diary.txt", 'r')
:        print viewdiary
:        print "---------------"
:        L = viewdiary.readlines()
:        print L
:        modified_str = string.replace(L, "\012", "<br>" )
:        print modified_str
:        viewdiary.close
:
:and the error I'm getting
:
:<open file 'c:\diary.txt', mode 'r' at 00B42920>
:---------------
:['this is a test\012', 'this is another test\012', 'one more test\012']
:Exception in Tkinter callback
:Traceback (most recent call last):
:  File "c:\python20\lib\lib-tk\Tkinter.py", line 1287, in __call__
:    return apply(self.func, args)
:  File "C:\python-code\diary-update\diary.py", line 71, in htmlize
:    modified_str = string.replace(L, "\012", "<br>" )
:  File "c:\python20\lib\string.py", line 363, in replace
:    return s.replace(old, new, maxsplit)
:AttributeError: replace