Wednesday, February 4, 2009

python tidbit on printing to string

I've been learning Python by using it in some data processing chores at work.
At some point, I wanted to be able to print to a string like you would using sprintf in C.

After some searching through the Python docs, I found StringIO which pretty much does what I wanted. There's also cStringIO, which is supposed to be a faster version of StringIO. But I'll save that for another day.


Edit: I realized that I didn't give an example how to use the StringIO module. Here's an example on how to print to string using the StringIO module.

No comments: