Friday, 15 April 2011

python - How can i remove the first character from a StringIO object? -


I could not understand it with Python documentation, so perhaps I would ask it here:

  Import string idio line = stringoo String Io () line. Written ('Hello world')   

Any method I can use, which is on the line [1:] line , So return line.getvalue () back to ello World

thanks . >

I can not figure out how to do this with line.getvalue , but You can use normal file objects such as stringio object, just search byte 1 and you read normally.

  gt; & Gt; Import Stringo & gt; & Gt; & Gt; Line = string IO.StringIO ()> & Gt; & Gt; Line.write ("Hello World") & gt; & Gt; & Gt; Line.Sec (0) >> gt; & Gt; Print Line.Getvalue () Hello World & gt; & Gt; & Gt; Line.sec (1)> gt; & Gt; & Gt; Print Line.Getvalue () Hello World & gt; & Gt; & Gt; Line.sec (1)> gt; & Gt; & Gt; Print Next (line) ello World & gt; & Gt; & Gt; Line.sec (1)> gt; & Gt; & Gt; Print Line Read () ello World    

No comments:

Post a Comment