This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: StringIO doc doesn't say it's sometimes read-only
Type: Stage:
Components: Documentation Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: hierro, rhettinger, tzot
Priority: normal Keywords:

Created on 2003-01-20 22:58 by hierro, last changed 2022-04-10 16:06 by admin. This issue is now closed.

Messages (6)
msg14133 - (view) Author: Mike Orr (hierro) Date: 2003-01-20 22:58
When StringIO is instantiated with an intial string:
StringIO("Hello, world!")
it's read-only; the write methods don't exist.  The
Python Library Reference should mention this.

If you instantiate StringIO without an initial string:
StringIO()
you get both read and write methods.
msg14134 - (view) Author: Χρήστος Γεωργίου (Christos Georgiou) (tzot) * Date: 2003-01-21 20:24
Logged In: YES 
user_id=539787

Did you import StringIO, or cStringIO as StringIO ?

This behaviour occurs only in cStringIO... if you do

m= cStringIO.StringIO("hello there")
n= cStringIO.StringIO()

you see that type(m) is cStringIO.StringI and n is 
cStringIO.StringO.

This is documented in the cStringIO module documentation.

 
msg14135 - (view) Author: Χρήστος Γεωργίου (Christos Georgiou) (tzot) * Date: 2003-01-21 20:24
Logged In: YES 
user_id=539787

Did you import StringIO, or cStringIO as StringIO ?

This behaviour occurs only in cStringIO... if you do

m= cStringIO.StringIO("hello there")
n= cStringIO.StringIO()

you see that type(m) is cStringIO.StringI and n is 
cStringIO.StringO.

This is documented in the cStringIO module documentation.

 
msg14136 - (view) Author: Mike Orr (hierro) Date: 2003-01-21 21:09
Logged In: YES 
user_id=239757

Yes, it's only cStringIO that does it.

However, the statenent about the type does not say anything
about which methods are available.  Many readers would
think, "I never have to compare the type to anything; this
doesn't apply to me."  How about a statement:

If you instantiate cStringIO.StringIO() without an argument,
the string is read-write.  But if you instantiate it with a
string argument: cStringIO.StringIO("abc"), it's read-only
and the write methods do not exist.  This applies only to
cStringIO; the corresponding objects in the StringIO module
are read-write in both cases.  [Then the paragraph about
InputType and OutputType.]
msg14137 - (view) Author: Χρήστος Γεωργίου (Christos Georgiou) (tzot) * Date: 2003-01-21 21:17
Logged In: YES 
user_id=539787

I find your suggestion informative, appropriate and nice :)
msg14138 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-01-31 05:23
Logged In: YES 
user_id=80475

Fixed the docs.
See Doc/lib/libstringio.tex 1.7
History
Date User Action Args
2022-04-10 16:06:09adminsetgithub: 37807
2003-01-20 22:58:25hierrocreate