By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,531 Members | 873 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,531 IT Pros & Developers. It's quick & easy.

StringIO objects sharing a buffer

P: n/a
Hi,

I want to implement a tokenizer for some syntax. So I thought I'd subclass
StringIO and make my new class return tokens on next().

However, if I want to read tokens from two places in the string in turns,
I'd either need to do some housekeeping of file pointers outside the
tokenizer class (which is ugly) or use two tokenizers on the same data
buffer (which seems impossible to me using my preferred approach as a
file-like object has exactly one file pointer).

Is there a way for multiple StringIO objects to share a buffer of data, or
do I have to give up on subclassing StringIO for this purpose? (An
alternative would be a tokenizer class that has a StringIO instead of
being one and do the file pointer housekeeping in there.)

--
Thomas
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Thomas Lotze wrote:
Is there a way for multiple StringIO objects to share a buffer of
data, or do I have to give up on subclassing StringIO for this
purpose? (An alternative would be a tokenizer class that has a
StringIO instead of being one and do the file pointer housekeeping
in there.)


I'm not sure if I understand the problem right, but there is a rule
of thumb:
Prefer delegation to inheritance. If you can use delegation, avoid
inheritance. Esp. on python, where (from the point of view of usage)
there is no distinction between delegation or inheritance.

Mathias
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.