Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107608

Re: Writing different sections into a file

From Grant Edwards <grant.b.edwards@gmail.com>
Newsgroups comp.lang.python
Subject Re: Writing different sections into a file
Date 2016-04-25 14:44 +0000
Message-ID <mailman.81.1461595506.32212.python-list@python.org> (permalink)
References <ad6f9260-0c01-4246-9be5-84b1d2470255@googlegroups.com> <nflagl$bbk$2@ger.gmane.org>

Show all headers | View raw


On 2016-04-25, Palpandi <palpandi111@gmail.com> 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 makes you think a temporary file isn't best?

> What is the better datatype to achieve this?

When in doubt, try the simplest approach first:

Use a string (or byte-string if it's not text) for each of the header,
body, and footer.  Append data to each as desired and then write them
out to a file when you're done.

If that's not workable, explain why, and we can tell you what to try
next (probably a stringio for each section, or a list of strings or
byte-strings for each section, or temporary files).

-- 
Grant Edwards               grant.b.edwards        Yow! Wait ... is this a FUN
                                  at               THING or the END of LIFE in
                              gmail.com            Petticoat Junction??

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Writing different sections into a file Palpandi <palpandi111@gmail.com> - 2016-04-25 00:30 -0700
  Re: Writing different sections into a file Peter Otten <__peter__@web.de> - 2016-04-25 10:48 +0200
  Re: Writing different sections into a file harirammanohar@gmail.com - 2016-04-25 02:50 -0700
  Re: Writing different sections into a file Karim <kliateni@gmail.com> - 2016-04-25 12:04 +0200
  Re: Writing different sections into a file Grant Edwards <grant.b.edwards@gmail.com> - 2016-04-25 14:44 +0000
  Re: Writing different sections into a file justin walters <walters.justin01@gmail.com> - 2016-04-25 08:00 -0700
  Re: Writing different sections into a file Karim <kliateni@gmail.com> - 2016-04-25 17:12 +0200

csiph-web