problem writing to file
Roeland Rengelink
r.b.rigilink at chello.nl
Mon May 14 13:15:27 EDT 2001
Christian Maus 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/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?
> Thanks in advance, christian
Hi Christian,
Are you sure that new_ldapentries contains strings.
If not, something like
testfile.write(str(new_ldapentries[line])+'\n')
should work. (Note the '\n' which is a special newline character)
By the way, you could write the loop also as:
for ldap_entry in new_ldapentries:
testfile.write(str(ldap_entry)+'\n')
Hope this helps,
Roeland Rengelink
--
r.b.rigilink at chello.nl
"Half of what I say is nonsense. Unfortunately I don't know which half"
More information about the Python-list
mailing list