Do I have to do StringIO.close()?

前端 未结 4 1235
旧时难觅i
旧时难觅i 2021-02-05 01:45

Some code:

import cStringIO

def f():
    buffer = cStringIO.StringIO()
    buffer.write(\'something\')
    return buffer.getvalue()

The docume

4条回答
  •  爱一瞬间的悲伤
    2021-02-05 02:21

    I wound up using a try block to handle it.

    import cStringIO
    
    def f():
        buffer = cStringIO.StringIO()
        try:
            buffer.write('something')
            return buffer.getvalue()
        finally:
            buffer.close()
    

提交回复
热议问题