Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40938
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: Apparent magic number problem |
| Date | 2013-03-09 09:51 +0100 |
| Organization | None |
| References | <khe0st$k45$1@theodyn.ncf.ca> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3120.1362819075.2939.python-list@python.org> (permalink) |
Colin J. Williams wrote:
> The program runs correctly under each version, but it runs more slowly
> under 3.2.
> This is probably due to the fact that the .pyc file is created for the
> Python 2.7 execution.
> When Python 3.2 is run it fails to create a new .pyc file and if the 2.7
> .pyc is offered directly a magic number problem is reported.
(1) .pyc files are only created if a module is imported
(2) The 2.7 .pyc file is put alongside the .py file whereas the 3.2 .pyc is
put into the __pycache__ subfolder. No clash can occur.
A simple example:
$ ls
mod.py
$ cat mod.py
print("hello world")
Run it; no pyc is created:
$ python2.7 mod.py
hello world
$ ls
mod.py
Import it using 2.7:
$ python2.7 -c 'import mod'
hello world
$ ls
mod.py mod.pyc
Import it using 3.2:
$ python3.2 -c 'import mod'
hello world
$ ls
mod.py mod.pyc __pycache__
$ ls __pycache__/
mod.cpython-32.pyc
Run the compiled code:
$ python2.7 mod.pyc
hello world
$ python3.2 __pycache__/mod.cpython-32.pyc
hello world
But I'm with Steven, it's unlikely that the module compilation phase is
responsible for a noticeable slowdown.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Apparent magic number problem "Colin J. Williams" <cjw@ncf.ca> - 2013-03-08 19:48 -0500
Re: Apparent magic number problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-09 05:22 +0000
Re: Apparent magic number problem Peter Otten <__peter__@web.de> - 2013-03-09 09:51 +0100
Re: Apparent magic number problem "Colin J. Williams" <cjw@ncf.ca> - 2013-03-09 10:16 -0500
Re: Apparent magic number problem Peter Otten <__peter__@web.de> - 2013-03-10 11:56 +0100
csiph-web