473,670 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

imputils - import problem modules from sys.modules

Hello,

I've created an archive import class (with the help of importers.py from the
python /demo/imputil dir) which imports packages and modules from a
dictionary. So far so good.

The problem is that every import statement after the code:

imputil.ImportM anager().instal l()
sys.path.insert (0, DictImporter(ar chive))
sys.path.insert (0, imputil.Builtin Importer())

tries to import from the dictionary and doesn't use the modules that were
imported before.

For example, I would like to use os in a module that's stored in the
dictionary. The import os statement tries to import os from the dictionary
and does not 'use' the already imported os module that is in the modules
list.

Is it possible to get access to both, already loaded modules in the modules
list and modules in the dictionary?

Regards,
Remy Cool
Jul 18 '05 #1
1 1762
Problem solved!!!

Switched to python 2.3 and created a class using the brand new
sys.path_hooks.

See python PEP302 for more info on this subject.

Remy
Hello,

I've created an archive import class (with the help of importers.py from
the python /demo/imputil dir) which imports packages and modules from a
dictionary. So far so good.

The problem is that every import statement after the code:

imputil.ImportM anager().instal l()
sys.path.insert (0, DictImporter(ar chive))
sys.path.insert (0, imputil.Builtin Importer())

tries to import from the dictionary and doesn't use the modules that were
imported before.

For example, I would like to use os in a module that's stored in the
dictionary. The import os statement tries to import os from the dictionary
and does not 'use' the already imported os module that is in the modules
list.

Is it possible to get access to both, already loaded modules in the
modules list and modules in the dictionary?

Regards,
Remy Cool


Jul 18 '05 #2

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

Similar topics

0
1989
by: John Roth | last post by:
I've found a case where it seems that Python is importing two copies of a module without any reason or indication. It took me a while to verify that this is what is occuring: I had to write a __import__ hook to trace the actual activity. The source code for the hook is below. There are several examples of the problem in the trace; this is one particularly juicy one. -----------Part 1 ---------------- '0059' Import 'TypeAdapter'...
13
2351
by: Robin Haswell | last post by:
Hey people I'm an experience PHP programmer who's been writing python for a couple of weeks now. I'm writing quite a large application which I've decided to break down in to lots of modules (replacement for PHP's include() statement). My problem is, in PHP if you open a database connection it's always in scope for the duration of the script. Even if you use an abstraction layer ($db = DB::connect(...)) you can `global $db` and bring...
4
1257
by: Christoph Zwerschke | last post by:
I'm currently investigating a problem that can hit you in TurboGears when Kid template modules are reloaded in the background, because in certain situations, global variables suddenly are set to None values. I tracked it down to the following behavior of Python. Assume you have a module hello.py like that: ---- hello. py ---- greeting = 'Hello!' def print_hello():
3
1821
by: Mohamed Yousef | last post by:
Hello , The problem I'm asking about is how can imported modules be aware of other imported modules so they don't have to re-import them (avoiding importing problems and Consicing code and imports ) Take Example :- in A.py :- import B print dir() # no problems we can see B which contain re module and C module
0
8386
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
8815
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8592
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
8661
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...
0
5686
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();...
0
4393
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2802
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
2
2044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1795
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.