convert string to input stream
titus at barik.net
Tue Aug 31 18:32:20 CEST 2004
I've used Google quite a bit in an attempt to find an answer to this
question, but have found no leads, possibly because I'm not sure I'm
wording my question properly. So I thought I'd try here.
Basically I have a function that accepts an input file stream as an
handle = open(SOME_FILE)
But occasionally, I end up with a string ("Hello world") that I need to
convert to a stream in order to pass it into this function. Perhaps
fake_handle = convert_to_handle("Hello world!")
so that it appears to this function to be a file handle. I've seen
functions in other languages that will take strings and convert them to
streams via IO Memory Buffers and such, but can't seem to find anything in
Python; or at least I don't know where to look.
One solution that I didn't like was to do the following:
1. Open a temporary file.
2. Write the string to that file.
3. Read it back.
Any suggestions are appreciated.
Titus Barik (titus at barik.net)
More information about the Python-list