[Tutor] String Replace.....

Budgester budgester@budgester.com
Sun, 28 Jan 2001 21:17:07 -0000


Hi people,

Okay i'm having a bit of problem,

Here's the code, after the file is written out from a Tkinter GUI

## 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

I can get replace to work via the interpreter but as soon as I put it into a
.py file
i get the above error, i'm sure it's something simple that I'm not seeing,
so a couple
of more knowledgeable eyes should be able to point me in the right
direction.

I can post the full code if needed.

Seperate note in the error report it says '(most recent call last)' i'm
assuming that it is the last command that is failing, is that right?

TIA

Budgester

mailto:budgester@budgester.com
http://www.budgester.com