Writing different sections into a file

Grant Edwards grant.b.edwards at gmail.com
Mon Apr 25 10:44:37 EDT 2016


On 2016-04-25, Palpandi <palpandi111 at 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??




More information about the Python-list mailing list