Advertisement

Python equivalent of stringstream?

Started by December 15, 2004 11:12 PM
1 comment, last by Zahlman 19 years, 9 months ago
I have recently been working on some scripts to parse various binary file formats, which can generally be viewed as a tree of "chunk" structures. For parsing it is convenient to be able to extract "sub-chunks" recursively, reading the chunk as if it were its own file. So, is there a good Python idiom for making a string behave like a file (rather, constructing some sort of file-like object using a string's data)? I currently am using my own (very ugly hack of a) wrapper implementing the file methods that I need, but I'm convinced I should be able to do better. But I couldn't find anything in the documentation (at least, nothing I can figure out how to put to good use)... any leads would be greatly appreciated [smile]
4.6 StringIO -- Read and write strings as files
4.7 cStringIO -- Faster version of StringIO
Advertisement
Thanks, I must be blind :s

This topic is closed to new replies.

Advertisement