X-Received: by 10.180.98.102 with SMTP id eh6mr2463755wib.7.1361139188533; Sun, 17 Feb 2013 14:13:08 -0800 (PST) X-Received: by 10.49.96.196 with SMTP id du4mr519651qeb.37.1361139188095; Sun, 17 Feb 2013 14:13:08 -0800 (PST) Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!209.85.212.216.MISMATCH!19no3112616wij.1!news-out.google.com!bp2ni41265wib.1!nntp.google.com!yu2no3604540wib.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Sun, 17 Feb 2013 14:13:07 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=70.196.64.154; posting-account=h3aEwQoAAACiuqX-oR3gvCVFm8lLHoWj NNTP-Posting-Host: 70.196.64.154 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Comparing types From: Rick Johnson Cc: python-list@python.org Injection-Date: Sun, 17 Feb 2013 22:13:08 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.python:39042 On Sunday, February 17, 2013 12:34:57 AM UTC-6, Jason Friedman wrote: > [...] > py> my_pattern =3D re.compile(s) > py> type(my_pattern) > > py> isinstance(my_pattern, _sre.SRE_Pattern) > Traceback (most recent call last): > File "", line 1, in > NameError: name '_sre' is not defined Both Steven and Terry provided answers to you question however you not stil= l understand why the line "isinstance(my_pattern, _sre.SRE_Pattern)" threw = a NameError.=20 Maybe you expected '_sre.SRE_Pattern' to be imported as a consequence of im= porting the "re" module? Hmm, not so. And you can even check these things y= ourself by using the global function: "dir". py> dir() ['__builtins__', '__doc__', '__name__', '__package__'] py> import re py> dir() ['__builtins__', '__doc__', '__name__', '__package__', 're'] As you can see only "re" is available after import, and Python does not loo= k /inside/ namespaces (except the __builtin__ namespace) to resolve names w= ithout a dotted path. But even /if/ Python /did/ look inside the "re" names= pace, it would not find the a reference to the module named "_sre" anyway! = Observe: =20 py> dir(re) ['DEBUG', 'DOTALL', 'I', 'IGNORECASE', 'L', 'LOCALE', 'M', 'MULTILINE', 'S'= , 'Scanner', 'T', 'TEMPLATE', 'U', 'UNICODE', 'VERBOSE', 'X', '_MAXCACHE', = '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__'= , '__version__', '_alphanum', '_cache', '_cache_repl', '_compile', '_compil= e_repl', '_expand', '_pattern_type', '_pickle', '_subx', 'compile', 'copy_r= eg', 'error', 'escape', 'findall', 'finditer', 'match', 'purge', 'search', = 'split', 'sre_compile', 'sre_parse', 'sub', 'subn', 'sys', 'template'] py> '_sre' in dir(re) False And if you look in the modules "_sre.py", "sre_parse.py", and "sre_constant= s.py you cannot find the symbol "SRE_Pattern" anywhere -- almost seems like= magic huh? Heck the only "_sre.py" file i could find was waaaay down here: ...\Lib\site-packages\isapi\test\build\bdist.win32\winexe\temp\_sre.py What were they doing, trying to bury it deeper than Jimmy Hoffa? Maybe one = of my fellow Pythonistas would like to explain that mess?