[Python-3000] Making more effective use of slice objects in Py3k
talin at acm.org
Thu Aug 31 07:36:43 CEST 2006
Josiah Carlson wrote:
> Talin <talin at acm.org> wrote:
>> The 'characters' data type would be particularly optimized for
>> character-at-a-time operations, i.e. building up a string one character
>> at a time. An example use would be processing escape sequences in
>> strings, where you are transforming the escaped string into its
>> non-escaped equivalent.
> That is already possible with array.array('H', ...) or array.array('L', ...),
> depending on the unicode width of your platform. Array performs a more
> conservative reallocation strategy (1/16 rather than 1/8), but it seems
> to work well enough. Combine array with wide character support in views,
> and we could very well have the functionality that you desire.
Well, one of the things I wanted to be able to do is:
'characters += str'
Or more precisely:
token_buf = characters()
token_buf += "example"
token_buf += "\n"
Now, an ordinary list would concatenate the string *object* onto the end
of the list; whereas the character array would concatenate the string
characters to the end of the character array. Also note that the __str__
method of the character array returns a vanilla string object of its
(What I am describing here is exactly the behavior of Java StringBuffer.)
More information about the Python-3000