Advertisement
gauravssnl

Introducing StringIO module

Sep 28th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. # Introducing StringIO
  2. # script converts string into a file object
  3.  
  4. import StringIO
  5. contents="gaurav is a bad boy"
  6. ssock=StringIO.StringIO(contents)
  7. print ssock.read()
  8. # Now nothing will be printed
  9. print ssock.read()
  10. # seek the file
  11. ssock.seek(0)
  12. # now read 15 characters
  13. print ssock.read(15)
  14. ssock.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement