Monday, October 8, 2012

Python StringIO -- need to call .close() ?


1
http://stackoverflow.com/questions/7996479/what-is-stringio-in-python-used-for-in-reality

StringIO gives you file-like access to strings, so you can use an existing module that deals with a file and change almost nothing and make it work with strings.
For example, say you have a logger that writes things to a file and you want to instead send the log output over the network. You can read the file and write its contents to the network, or you can write the log to a StringIO object and ship it off to its network destination without touching the filesystem. StringIO makes it easy to do it the first way then switch to the second way.




2 Manually closing stringIO is necessary. asdf.close()
http://stackoverflow.com/questions/9718950/do-i-have-to-do-stringio-close

This was a major headache in some legacy sax-parser script we solved by closing the StringIO manually.
The "out-of-scope" close didn't work. It just waited for the timeout-limit.

No comments:

Post a Comment