problem writing to file

Rainy sill at
Mon May 14 17:50:59 CEST 2001

On Mon, 14 May 2001 16:57:39 +0200, Christian Maus <maus at> wrote:
> Hi, 
> 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/", line 764, in __call__
>     		    return apply(self.func, args)
>   		  File "python/", 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?
> Thanks in advance, christian

Did you do from os import *? os has a function called open.. Morale: do
not use import *.

I'll give you anything, everything if you want things
        - Syd

More information about the Python-list mailing list