diff Lib/StringIO.py @ 23456:64eb119b816d 2.2

Add docstrings excerpted from the library reference. Closes patch 556161.
author Raymond Hettinger <python@rcn.com>
date Wed, 15 May 2002 03:50:31 +0000
parents 165e20ac0ab1
children a0005d26773d
line wrap: on
line diff
--- a/Lib/StringIO.py	Tue May 14 14:07:12 2002 +0000
+++ b/Lib/StringIO.py	Wed May 15 03:50:31 2002 +0000
@@ -37,6 +37,17 @@
 __all__ = ["StringIO"]
 
 class StringIO:
+    """class StringIO([buffer]) 
+    
+    When a StringIO object is created, it can be initialized to an existing
+    string by passing the string to the constructor. If no string is given,
+    the StringIO will start empty. 
+
+    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 7-bit ASCII (that use the 8th bit) will cause
+    a UnicodeError to be raised when getvalue() is called. 
+    """
     def __init__(self, buf = ''):
         # Force self.buf to be a string or unicode
         if type(buf) not in types.StringTypes:
@@ -52,6 +63,7 @@
         return iter(self.readline, '')
 
     def close(self):
+        """Free the memory buffer."""
         if not self.closed:
             self.closed = 1
             del self.buf, self.pos
@@ -165,6 +177,16 @@
             raise ValueError, "I/O operation on closed file"
 
     def getvalue(self):
+        """
+        Retrieve the entire contents of the "file" at any time before
+        the StringIO object's close() method is called.
+
+        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 7-bit ASCII (that use the
+        8th bit) will cause a UnicodeError to be raised when getvalue()
+        is called. 
+        """
         if self.buflist:
             self.buf += ''.join(self.buflist)
             self.buflist = []