faqts : Computers : Programming : Languages : Python : Common Problems : Strings

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 15 people (27%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

Is there a StringBuffer-Class (as in Java, a mutable string if you want) in Python?

May 12th, 2006 20:37
Reed O'Brien, Marco Aschwanden,


Python strings are immutable. Period.
Maybe you want a memory file?
>>> import StringIO
>>> x = 'This is a string'
>>> buffer = StringIO.StringIO()
>>> buffer.write(x)
>>> y = 'More string I want to add to the buffer'
>>> buffer.write(y)
>>> print buffer.getvalue()
This is a string
More string I want to add to the buffer
>>> buffer.close()