diff options
author | Raymond Hettinger <python@rcn.com> | 2002-05-15 02:56:03 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2002-05-15 02:56:03 (GMT) |
commit | d1fa3db52de5f337e9aae5f3baad16fe62da2d0f (patch) | |
tree | 95180a631b52bb190154b11559d0bfdcdbca17cd /Lib/StringIO.py | |
parent | 55956c93615855b47cfc5bf9ddc2633a5f73044c (diff) | |
download | cpython-d1fa3db52de5f337e9aae5f3baad16fe62da2d0f.zip cpython-d1fa3db52de5f337e9aae5f3baad16fe62da2d0f.tar.gz cpython-d1fa3db52de5f337e9aae5f3baad16fe62da2d0f.tar.bz2 |
Added docstrings excerpted from Python Library Reference.
Closes patch 556161.
Diffstat (limited to 'Lib/StringIO.py')
-rw-r--r-- | Lib/StringIO.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/StringIO.py b/Lib/StringIO.py index 38b3e36..b8cba32 100644 --- a/Lib/StringIO.py +++ b/Lib/StringIO.py @@ -37,6 +37,17 @@ except ImportError: __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 not isinstance(buf, types.StringTypes): @@ -52,6 +63,8 @@ class StringIO: 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 +178,16 @@ class StringIO: 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 = [] |