Quick Reference from module doc strings.
Ron Adam
rrr at ronadam.com
Tue May 17 19:54:23 EDT 2005
Scott David Daniels wrote:
> Ron Adam wrote:
>
>> ...What would be the advantage of using StringIO over list.append with
>> ''.join()?
>
> The advantage is more in using a function that prints as it goes
> rather than building up a large string to print. I would call the
> print function at the bottom (with None as the print destination),
> rather than printing the result of calling the string function.
The reason I return the string to the calling function instead of
printing it, is the person using it may not want to print it. They may
want to send it to a file, or process it further before printing it.
Same with the individual records.
> I just did the StringIO thing to show you that printing as you go
> needn't mean you cannot get the string value without duplicating code.
>
> --Scott David Daniels
> Scott.Daniels at Acm.Org
I've used IO Streams,(">>" and "<<"), before in C, where I was
continually reading to and writing from a buffer as I went. (Back when
memory was often smaller than most files.)
I haven't played around with the StringIO module yet, and this will
probably be more of a database application rather than just formatting
input for output. So for now the strings operations are fine until I
better decide how they will get used.
Maybe further down the road I'll convert them to, or have a need for
serialized objects, so I'll keep the STringIO module in mind. :-)
Cheers,
_Ron
More information about the Python-list
mailing list