From: Jeff N. <jn...@ac...> - 2006-05-27 14:59:40
|
I can just use: isinstance("s", (StringType, UnicodeType)) but it does seem like Jython has a basestring type from which both StringType and UnicodeType inherit. For instance: Jython 2.2a1 on java1.5.0_06 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> s =3D "str" >>> c =3D s.__class__ >>> c.__bases__ (<type 'basestring'>,) >>> u =3D u"str" >>> u.__class__.__bases__ (<type 'basestring'>,) I was just thinking it would be more compact and faster to check against basestring but it isn't in the types module or a builtin. I could add it to the types module but that wouldn't be portable to CPython. Anyway thanks, Jeff. > -----Original Message----- > From: Frank Wierzbicki [mailto:fwi...@gm...]=20 > Sent: Friday, May 26, 2006 6:21 PM > To: Jeff Norton > Cc: jyt...@li... > Subject: Re: [Jython-users] basestring >=20 > Jython does not have a basestring type, and probably never=20 > will. It is kind of an implementation detail in CPython --=20 > and will disappear in Python3000 anyway (although the=20 > following probably won't work in Py3000 eithen). You can get=20 > the some effect by using: >=20 > >>> from types import StringTypes > >>> str in StringTypes > 1 > >>> unicode in StringTypes > 1 > >>> type("s") in StringTypes > 1 > >>> type(u"s") in StringTypes > 1 >=20 >=20 > On 5/26/06, Jeff Norton <jn...@ac...> wrote: > > > > > > > > > > I've got a lot of Python 2.3 code that uses the basestring=20 > builtin type. > > E.g. > > > > if isinstance(obj, basestring): > > > > Jython 2.2a1 doesn't seeme to have a basestring builtin.=20 > Anyone know=20 > > how to get access to it? > > > > Thanks, > > > > Jeff Norton. >=20 |