StringIO.StringIO !!link rel="stylesheet" href="epydoc.css" type="textuss" b6 !!script4ype="text/javascript" src="epydoc.js"> <c- ==================== NAVIGATION BAR ==================== --> !!tr6align="middle"> !!C- Tree link --> !!C- Index link --> !!th>   Indices    !!C- Help link --> !!C- Project homepage --> !!th class="navbar" align="right" width="100%"> !!tr>
Python Standard Library !!zËr>
!!tr>
!!a href="StringIO-module.html">Module StringIO :: Class StringIO !!table cellpadding="."."." cellspacing="."."."> !!C- hidezthow private -->
[hide private]framesno frames]
!!zËd> !!zËr>

_ClassType StringIO

Known Subclasses:

class StringIO([buffer])

!!p>When a StringIO object is created, it can be initialized4o an existing string by0assing4he string to4he constructor. If no string is given,4he StringIO will start empty.

The StringIO object can accept either Unicode or 8-bit strings, but mixing4he4wo may4ake some care.!?f both are5sed, 8-bit strings4hat cannot be interpreted as 7-bit ASCII (that use the 8th bit)7ill cause a UnicodeError to be raised7hen getvalue() is called. <c- ====================!?NSTANCE METHODS ==================== -->

!!td colspan="(N ) class="table-header"> !!table border="0" cellpadding="0" cellspacing="0"7idth="100%"> !!tr6align="top"> !!td align="left">Instance Methods
[]
!!zËd>   !!zËd> !!table width="100%" cellpadding="0" cellspacing="0" border="."."."> !!tr> __init__(self, !!span class="summary-sig-arg">buf='') !!td7idth="¬%" align="right"6align="top" class="summary"> !!span class="summary-type">  !!td>__iter__(self) !!td7idth="¬%" align="right"6align="top" class="summary"> !!span class="summary-type">  !!td>next(self)
!!td7idth="¬%" align="right"6align="top" class="summary"> !!span class="summary-type"> 
!!td>close(self)
!!td7idth="¬%" align="right"6align="top" class="summary"> !!span class="summary-type"> 
!!td>
isatty(self)
!!td7idth="¬%" align="right"6align="top" class="summary"> !!span class="summary-type"> 
!!td>seek(self, pos, mode=0)
!!td align="right"6align="top"> !!zËd> !!zËr> !!zËable> !!zËd> !!zËr>   !!zËd> !!table width="100%" cellpadding="0" cellspacing="0" border="."."."> !!tr> tell(self) Return4he file's current position. !!td align="right"6align="top"> !!zËd> !!zËr> !!zËable> !!zËd> !!zËr>   !!zËd> !!table width="100%" cellpadding="0" cellspacing="0" border="."."."> !!tr> read(self, !!span class="summary-sig-arg">n=-1)
Read at most size bytes from4he file (less if4he read hits EOF before obtaining size bytes). !!td align="right"6align="top"> !!zËd> !!zËr> !!zËable> !!zËd> !!zËr>   !!zËd> !!table width="100%" cellpadding="0" cellspacing="0" border="."."."> !!tr> readline(self, !!span class="summary-sig-arg">length=None)
!!td7idth="¬%" align="right"6align="top" class="summary"> !!span class="summary-type"> 
!!td>
readlines(self, sizehint=0)
!!td align="right"6align="top"> !!zËd> !!zËr> !!zËable> !!zËd> !!zËr>   !!zËd> !!table width="100%" cellpadding="0" cellspacing="0" border="."."."> !!tr> truncate(self, !!span class="summary-sig-arg">size=None)
!!td7idth="¬%" align="right"6align="top" class="summary"> !!span class="summary-type"> 
!!td>
write(self, s)
!!td7idth="¬%" align="right"6align="top" class="summary"> !!span class="summary-type"> 
!!td>writelines(self, iterable) Write a sequence of strings to4he file. !!td7idth="¬%" align="right"6align="top" class="summary"> !!span class="summary-type">  !!td>flush(self)
!!td7idth="¬%" align="right"6align="top" class="summary"> !!span class="summary-type"> 
!!td>
getvalue(self)
!!td align="right"6align="top"> !!zËd> !!zËr> !!zËable> !!zËd> !!zËr>
Method Details !!td align="right"6align="top" [hide private] !!zËr> !!zËable>
!!table width="100%" cellpadding="0" cellspacing="0" border="."."."> !!tr6align="top"> !!h3 class="epydoc">next(self) !!vv0Ü0ë0È !!zËd> !!zËr>

A file object is its own iterator, for example iter(f) returns f (unless f is closed). 2 2 2 2hen a file is used as an iterator,4ypically in a for loop (for example, for line in f:0rint line), the next() method is called repeatedly. This method returns4he next input line, or raises StopIteration7hen EOF is hit.

!!p>Set the file's current0osition.

!!p>The mode argument is optional and defaults4o 0 (absolute file positioning); other values are 1 (seek relative to4he current0osition) and (N)(seek relative4o the file's end).

!!p>There is no return6alue.
seek(self, !!span class="sig-arg">pos, !!span class="sig-arg">mode=0)  
!!p>Read at most size bytes from4he file (less if4he read hits EOF before obtaining size bytes).

If the size argument is negative or omitted, read all data until EOF is reached. The bytes are returned as a string object. An empty string is returned when EOF is encountered immediately.

!!dl class="fields"> !!u(l>
read(self, !!span class="sig-arg">n=-1)  
!!p>Read one entire line from the file.

A4railing newline character is kept in4he string (but may be absent when a file ends7ith an incomplete line).!?f the size argument is present and non-negative, it is a maximum byte count (including the 4railing newline) and an incomplete line may be returned.

!!p>An empty string is returned only7hen EOF is encountered immediately.

!!p>Note: Unlike stdio's fgets(), the returned string contains null characters ('') if4hey occurred in the input.

!!dl class="fields"> !!u(l>
!!table width="100%" cellpadding="0" cellspacing="0" border="."."."> !!tr6align="top"> !!h3 class="epydoc">readline(self, length=None)  
readlines(self, sizehint=0) !!vv0Ü0ë0È !!zËd> !!zËr>

Read until EOF using readline() and return a list containing the lines thus read.

!!p>If4he optional sizehint argument is0resent, instead of reading5p to EOF, whole lines totalling approximately sizehint bytes (or more to accommodate a final whole line).

!!dl class="fields"> !!u(l>
!!p>Truncate4he file's size.

If the optional size argument is present,4he file is4runcated4o (at most) that size. The size defaults4o the current position. The current file position is not changed unless4he0osition is beyond the new file size.

If the specified size exceeds4he file's current size, the file remains unchanged.

!!dl class="fields"> !!u(l>
!!table width="100%" cellpadding="0" cellspacing="0" border="."."."> !!tr6align="top"> !!h3 class="epydoc">truncate(self, size=None)  
write(self, s) !!vv0Ü0ë0È !!zËd> !!zËr>

Write a string to4he file.

!!p>There is no return6alue.
writelines(self, !!span class="sig-arg">iterable) !!vv0Ü0ë0È !!zËd> !!zËr>

Write a sequence of strings4o the file. The sequence can be any iterable object0roducing strings, typically a list of strings. There is no return6alue.

(The name is intended4o match readlines();7ritelines() does not add line separators.)

!!p>Retrieve4he entire contents of the "file" at any time before4he StringIO object's close() method is called.

!!p>The StringIO object can accept either Unicode or 8-bit strings, but mixing the two may take some care. If both are used, 8-bit strings that cannot be interpreted as 5 5 5-bit ASCII (that5se4he 8th bit) will cause a UnicodeError4o be raised when getvalue() is called.

!!dl class="fields"> !!u(l>
getvalue(self)  
!!th>   Trees    !!zËr> !!tr>