How do I save the contents of a text buffer

google at orcon.net.nz google at orcon.net.nz
Sat Feb 17 18:47:20 EST 2007


Hi,

I'm using Python with pygtk and have this problem - I have read the
contents of a file into the text buffer with this code,

        infile = open("mytextfile", "r")
        if infile:
            string = infile.read()
            infile.close()
            textbuffer.set_text(string)

As a test, I tried to write the buffer back to a file with this code
but did not work,

	outfile = open("newbannedsitelist", "w")
	outfile.write(textbuffer.get_text(0, 1000,
include_hidden_chars=True))
	outfile.close()

What I want to know is how do I write the contents of the text buffer
back to a file?

Thanks




More information about the Python-list mailing list