Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39043
| 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 | <rantingrickjohnson@gmail.com> |
| 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 | <mailman.1881.1361082907.2939.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=70.196.64.154; posting-account=h3aEwQoAAACiuqX-oR3gvCVFm8lLHoWj |
| References | <mailman.1881.1361082907.2939.python-list@python.org> |
| 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 <rantingrickjohnson@gmail.com> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Message-ID | <mailman.1907.1361139192.2939.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On Sunday, February 17, 2013 12:34:57 AM UTC-6, Jason Friedman wrote:
> [...]
> py> my_pattern = re.compile(s)
> py> type(my_pattern)
> <class '_sre.SRE_Pattern'>
> py> isinstance(my_pattern, _sre.SRE_Pattern)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> NameError: name '_sre' is not defined
Both Steven and Terry provided answers to you question however you not still understand why the line "isinstance(my_pattern, _sre.SRE_Pattern)" threw a NameError.
Maybe you expected '_sre.SRE_Pattern' to be imported as a consequence of importing the "re" module? Hmm, not so. And you can even check these things yourself 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 look /inside/ namespaces (except the __builtin__ namespace) to resolve names without a dotted path. But even /if/ Python /did/ look inside the "re" namespace, it would not find the a reference to the module named "_sre" anyway! Observe:
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', '_compile_repl', '_expand', '_pattern_type', '_pickle', '_subx', 'compile', 'copy_reg', '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_constants.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?
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll 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