Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39025
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Comparing types |
| Date | 2013-02-17 04:42 -0500 |
| References | <CANy1k1iduaZfBfUbVjDP3iHx49-cjKU+50QETgAr_VSXr2eCfg@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1891.1361094162.2939.python-list@python.org> (permalink) |
On 2/17/2013 1:34 AM, Jason Friedman wrote: > I want to tell whether an object is a regular expression pattern. > > Python 3.2.3 (default, Oct 19 2012, 20:10:41) > [GCC 4.6.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import re >>>> s = "hello" >>>> type(s) > <class 'str'> >>>> isinstance(s, str) > True >>>> my_pattern = re.compile(s) >>>> type(my_pattern) > <class '_sre.SRE_Pattern'> The .__name__ attribute of the class is '_sre.SRE_Pattern' >>>> isinstance(my_pattern, _sre.SRE_Pattern) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > NameError: name '_sre' is not defined but the class is not bound to a (builtin) name, including not to _sre.SRE_Pattern -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Comparing types Terry Reedy <tjreedy@udel.edu> - 2013-02-17 04:42 -0500
csiph-web