Possible to write a Unicode*like* object?
Michael Hudson
mwh at python.net
Tue Feb 4 13:00:16 EST 2003
Just <just at xs4all.nl> writes:
> In article <7h3znpctbm4.fsf at pc150.maths.bris.ac.uk>,
> Michael Hudson <mwh at python.net> wrote:
>
> > Just <just at xs4all.nl> writes:
> >
> > > In the PyObjC project (a bridge between Python and Objective-C, and/or
> > > Cocoa really, OSX's GUI stuff) there's currently a discussion about
> > > whether to _convert_ NSString instances (the Cocoa string class) to
> > > Python (unicode) strings or to wrap the original instance that would
> > > make it string-like. For 8-bit strings wrapping is probably not a big
> > > deal, the buffer interface makes this work quite transparently, but I
> > > have no clue whether this is possible for unicode strings as well. Any
> > > ideas?
> >
> > I think you can return unicode data through the buffer interface too,
> > can't you? In any case, I'm a bit unsure what exactly you're asking.
>
> I'm not sure sure myself, either... I think an example could be: can I
> write a class (in C) that will be treated just like a unicode object, eg
> when doing pattern matching with re?
>From staring at the source, I'd guess so.
Actually, yes: someone already has.
>>> re.match('(a)|b', array.array('u', u'a string')).groups()
(array('u', u'a'),)
> I tend to think we shouldn't even try this and we should simply build a
> true unicode object, but there are voices in the project that say we
> should avoid the conversion at all cost. I wouldn't be too unhappy about
> that, provided it can work reasonably transparently, which I doubt.
See above. I'm not sure there's an alternative to "suck it and see".
Cheers,
M.
--
I'm sorry, was my bias showing again? :-)
-- William Tanksley, 13 May 2000
More information about the Python-list
mailing list