On 25/04/2016 09:30, Palpandi wrote:
Hi, I need to write different sections into a file. At any point of time, content can be added to any section. I don't want keep each section into a temporary file. What is the better way to store the contents of each section and write them into a file at the end? What is the better datatype to achieve this? Thanks and Regards, Palpandi
Use Stringio: - from cStringIO import StringIO content = StringIO() # Header content.write('; Header\n') content.write('; Body'\n) content.write('; Footer\n') open('my_file', 'wb').write(content.getvalue()) - Karim -- https://mail.python.org/mailman/listinfo/python-list