Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'importing': 0.04; '(except': 0.05; 'python': 0.09; 'function:': 0.09; 'imported': 0.09; 'nameerror:': 0.09; 'path.': 0.09; 'terry': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; "'__doc__',": 0.16; "'__file__',": 0.16; '__builtin__': 0.16; 'doing,': 0.16; 'dotted': 0.16; 'module?': 0.16; 'namespace,': 0.16; 'pythonistas': 0.16; 'threw': 0.16; 'wrote:': 0.17; 'module': 0.19; 'trying': 0.21; 'import': 0.21; '"",': 0.22; 'defined': 0.22; 'cc:2**0': 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'so.': 0.24; 'cc:addr:python.org': 0.25; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:[ 10': 0.26; 'skip:" 20': 0.26; '(most': 0.27; 'question': 0.27; 'consequence': 0.29; 'steven': 0.29; 'skip:_ 10': 0.29; 'maybe': 0.29; "skip:' 10": 0.30; 'file': 0.32; 'could': 0.32; 'anywhere': 0.33; 'symbol': 0.33; 'traceback': 0.33; 'received:google.com': 0.34; 'false': 0.35; 'jason': 0.35; 'expected': 0.35; 'received:209.85': 0.35; 'explain': 0.36; 'but': 0.36; 'modules': 0.36; 'resolve': 0.37; 'does': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'things': 0.38; 'skip:" 10': 0.40; 'here:': 0.62; 'yourself': 0.77; '2013': 0.84; 'huh?': 0.84; 'jimmy': 0.84 X-Received: by 10.49.96.196 with SMTP id du4mr519651qeb.37.1361139188095; Sun, 17 Feb 2013 14:13:08 -0800 (PST) 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 References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 70.196.64.154 MIME-Version: 1.0 Subject: Re: Comparing types From: Rick Johnson To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361139192 news.xs4all.nl 6874 [2001:888:2000:d::a6]:37026 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39043 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?