474,116 Members | 9,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

import with "python -O"

Hi there !

I'm usually relying on the fact that pyc file are autogenerated when
necessary (ie usually when the py file has been modified since the pyc
creation). However, it doesn't seems to work correctly when the -O option
is given to the interpreter :

syt@musca:test$ python
Python 2.3.4 (#2, Sep 24 2004, 08:39:09)
[GCC 3.3.4 (Debian 1:3.3.4-12)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
..>>> from logilab import pylint
..>>> pylint.__file__
'/home/syt/cvs_work/logilab/pylint/__init__.pyc'
..>>>
syt@musca:test$ python -O
Python 2.3.4 (#2, Sep 24 2004, 08:39:09)
[GCC 3.3.4 (Debian 1:3.3.4-12)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
..>>> from logilab import pylint
..>>> pylint.__file__
'/usr/lib/python2.3/site-packages/logilab/pylint/__init__.pyo'

The PYTHONPATH has not changed but the interpreter seems to take the first
pyo it finds, even if there is a more recent .py file before in the python
path. Should this behaviour be considered as normal ?

--
Sylvain Thénault LOGILAB, Paris (France).

http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Jul 18 '05 #1
1 1435
On Thu, 30 Dec 2004 16:56:17 +0100, Sylvain Thenault wrote:
Hi there !

I'm usually relying on the fact that pyc file are autogenerated when
necessary (ie usually when the py file has been modified since the pyc
creation). However, it doesn't seems to work correctly when the -O option
is given to the interpreter :

syt@musca:test$ python
Python 2.3.4 (#2, Sep 24 2004, 08:39:09)
[GCC 3.3.4 (Debian 1:3.3.4-12)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
.>>> from logilab import pylint
.>>> pylint.__file__
'/home/syt/cvs_work/logilab/pylint/__init__.pyc'
.>>>
syt@musca:test$ python -O
Python 2.3.4 (#2, Sep 24 2004, 08:39:09)
[GCC 3.3.4 (Debian 1:3.3.4-12)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
.>>> from logilab import pylint
.>>> pylint.__file__
'/usr/lib/python2.3/site-packages/logilab/pylint/__init__.pyo'

The PYTHONPATH has not changed but the interpreter seems to take the first
pyo it finds, even if there is a more recent .py file before in the python
path. Should this behaviour be considered as normal ?


ok, my fault... The problem was that the logilab subdirectory didn't have
anymore the __init__.py file, but only the __init__.pyc file. Adding it
fix the problem.
Thank you four your attention.

--
Sylvain Thénault LOGILAB, Paris (France).

http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1692
by: Daniel Holth | last post by:
Hello! I am trying to embed Python into an xmms plugin using Debian/unstable/i386, gcc 3.3.1 and Python 2.2.3+. The plugin is a shared library loaded by xmms. The plugin is dynamically linked with the python library. Running scripts works but when I try to import python extensions I get these kinds of errors: Traceback (most recent call last): File "<string>", line 1, in ?
2
2135
by: Bill Janssen | last post by:
Is the ability to import Python modules from zip files in 2.3 documented anywhere? I looked in the Language ref at the "import" statement and in the Library Ref under "ZipFile" module. I'd like to know the specifics of arcnames in the Python zipfiles, such as which character is used to separate path parts. Bill
7
4463
by: Andy Bulka | last post by:
Whilst almost responding to the 'dream project' thread I decided that this post warranted its own thread. What about a solid UML tool with round trip functionality for the Python Community? Some attempts at reverse engineering python are PyReverse http://www.logilab.org/projects/pyreverse/ PyUt http://pyut.sourceforge.net/ PyNSource http://www.atug.com/andypatterns/pynsource.htm Boa Constructor ...
1
2342
by: Choo Zhi Min | last post by:
Hi, I apologize in advance if this is not the right place to ask Python RPM related question. I don't know which is the right mailing list to ask. I was trying to verify Python 2.3.3 RPM packages on Fedora 1. I downloaded the key from http://www.python.org/ftp/python/2.3.3/rpms/KRUD-GPG-KEY, but rpm --import gave error when importing the keys. I used gpg --import and also got the same problem.
1
1742
by: Keith Moore | last post by:
I'm a Python newbie, Can anyone show me an example of how to import a python class into a C++ program? I am able to use PyImort_ImportModule to import a module, and PyObject_GetAttrString to import the function from the module. Now I converted that module to a class. I need to import methods from that class into my C++ program. Help!!!
4
2446
by: gsocks | last post by:
hello, i have a problem. i would like to import python files above and below my current directory. i'm working on /home/foo/bar/jar.py i would like to import /home/foo/car.py and /home/foo/bar/far.py
2
2596
by: Jon | last post by:
It appears that (windows) python searches in the current working directory before looking in the local site-packages directory, or that '.' comes first in sys.path? The problem arises when I made the mistake of running a test program from the same directory where I built and installed my package. Python uses the package from the current directory, which misses the pyd files, instead of the site-packages package which has them installed. ...
3
12116
by: yinglcs | last post by:
Hi, i have 2 python files in *different directory* , how can I import python functions from 1 python file to another? i get this error: import task ImportError: No module named task/ Thank you.
0
1136
by: Gabriel Genellina | last post by:
En Fri, 13 Jun 2008 20:01:56 -0300, Dan Yamins <dyamins@gmail.com> escribió: Note that if you execute dir() at this point, you'll see the Operations name, *not* Operations.archive. The statement "import Operations.archive" first tries to locate and load a module named Operations - and *that* name is added to the current namespace, not Operations.archive (which is an invalid name by itself).
4
2105
ChrisWang
by: ChrisWang | last post by:
Dear all, I am reading the book "Core Python Programming". In the chapter talking about modules, it says the modules should follow this ordering: import Python Standard Library modules import Python third party modules import Application-specific modules
0
10487
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
12377
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
12390
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
11278
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8894
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
8055
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
6889
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
7031
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.