how to save a gtktextbuffer content in file

Posted by user1565593 on Ask Ubuntu See other posts from Ask Ubuntu or by user1565593
Published on 2012-11-20T19:22:39Z Indexed on 2012/11/22 11:14 UTC
Read the original article Hit count: 332

i tried to save sengtktextbuffer content in a file. my code seens working but i have a problem in file.

some characters are unreadable in outfile outfile

my code:

def on_save_clicked(self, widget, data=None):
    start = self.textbuffer.get_start_iter()
    end = self.textbuffer.get_end_iter()

    this = self.textbuffer.get_text(start, end, False)
    format = self.textbuffer.register_serialize_tagset(this)
    data = self.textbuffer.serialize(self.textbuffer, format, start, end)

    outfile = open("/home/christophe/toto.txt", "w")
    outfile.write(data)
    outfile.close()

what is wrong in my code?

thanks for your help

© Ask Ubuntu or respective owner

Related posts about application-development

Related posts about pygtk