Fail to get data on using read() of StringIO in python

后端 未结 2 752
余生分开走
余生分开走 2021-01-31 06:42

Using Python2.7 version. Below is my sample code.

import StringIO
import sys

buff = StringIO.StringIO()
buff.write(\"hello\")
print buff.read()
<
2条回答
  •  滥情空心
    2021-01-31 07:21

    In [38]: out_2 = StringIO.StringIO('not use write') # be initialized to an existing string by passing the string to the constructor
    
    In [39]: out_2.getvalue()
    Out[39]: 'not use write'
    
    In [40]: out_2.read()
    Out[40]: 'not use write'
    

    or

    In [5]: out = StringIO.StringIO()
    
    In [6]: out.write('use write')
    
    In [8]: out.seek(0)
    
    In [9]: out.read()
    Out[9]: 'use write'
    

提交回复
热议问题