problem writing to file
Remco Gerlich
scarblac at pino.selwerd.nl
Mon May 14 11:10:58 EDT 2001
Christian Maus <maus at netz.klinik.uni-mainz.de> wrote in comp.lang.python:
> I have a strange problem when I try to write to a file. I created a list
> named named new_ldapentries. I create a file object in write mode:
> testfile = open('/tmp/testfile', 'w')
> then I go through the elements of my list and try to write them to the
> file:
> for i in range(len(new_ldapentries)):
> testfile.write(new_ldapentries[i])
> testfile.close()
> When I run the script I get the following error:
> Exception in Tkinter callback
> Traceback (innermost last):
> File "/usr/lib/python1.5/lib-tk/Tkinter.py", line 764, in __call__
> return apply(self.func, args)
> File "python/emailmanager.py", line 333, in writeLDAPentry
> testfile.write(new_ldapentries[line])
> TypeError: read-only buffer, instance
>
> The strange thing is when I replace the new_ldapentries[line] with any
> String like 'hello' everything works fine.
>
> Has anybody a idea where I made a mistake?
Did you use from ... import * somewhere? I think your open() function isn't
the usual builtin 'open file' function anymore. Try printing repr(open)
where that happens.
--
Remco Gerlich
More information about the Python-list
mailing list