Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39014

Comparing types

Date 2013-02-16 23:34 -0700
Subject Comparing types
From Jason Friedman <jsf80238@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1881.1361082907.2939.python-list@python.org> (permalink)

Show all headers | View raw


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'>
>>> isinstance(my_pattern, _sre.SRE_Pattern)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '_sre' is not defined

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Comparing types Jason Friedman <jsf80238@gmail.com> - 2013-02-16 23:34 -0700
  Re: Comparing types Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-17 19:38 +1100
  Re: Comparing types Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-17 14:13 -0800
    Re: Comparing types Chris Angelico <rosuav@gmail.com> - 2013-02-18 17:50 +1100
  Re: Comparing types Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-17 14:13 -0800

csiph-web