473,662 Members | 2,596 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Request for loading zipped modules in some context

When trying to import a module from a filesystem directory there are
several possibilities. Most obviously one can use an import statement
but if this is not sufficient one has also API functions. However
these API functions don't seem to be consistent with each other.

If one uses the builtin __import__ function one can import the module
in some context i.e. one can pass locals and globals:

__import__( name[, globals[, locals[, fromlist[, level]]]])

If one uses the imp module instead one has several different
possibilities to load a module ( load_source, load_compiled ) but none
of them imports the module in some context.

The situation becomes worse when using zipimport. The zipimport module
provides methods get_code and load_module.
>>import zipimport
importer = zipimport.zipim porter("myzipar chive.zip")
mod = importer.load_m odule("mymodule ")
mod
<module 'mymodule' from 'myziparchive.z ip\mymodule.py' >

Using load_module returns a module object. One cannot initialize the
module in some context though. One can also use get_code and use a
code object:
>>mod_code = importer.get_co de("mymodule")
mod_code
<code object <moduleat 00B05260, file "myziparchive.z ip
\mymodule.py", line 1>
>>eval(mod_code , locals(), globals())
One can evaluate the code object but this won't give you much. It
won't magically transform the code object into a module object being
returned and cached. Creating a module object from a code object isn't
possible AFAIK. The get_code method doesn't seem to be particular
usefull.

I'd like to see things being made more uniform - but uniform in the
sense of providing the most powerfull options all over the place.
Jan 5 '08 #1
0 793

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

Similar topics

0
1294
by: fowlertrainer | last post by:
Hello ! I have used mod_python. But it is don't reload my modules when I editing them. I try with this: -------------------- # Module importer import os import traceback
68
3744
by: Grant Edwards | last post by:
Let's say I use a GPL'd python module (e.g. something installed in site-packages) in an application. Let's also say I use py2exe to package and distribute said application. Is what I'm distributing a "derived work" of the GPL'd python? Or is py2exe's packaging of the module's .pyc file and my application code's .pyc files a "mere aggregation" so that I only have to provide source code for the GPL'ed module and not
5
2636
by: Filip | last post by:
Hello, (ASP.NET c#) I want to put some common functions into one class and within this class I need to have access to the Session, Request and Response. This class is not page behind file! I keep trying all sorts of namespaces, but to no avail. Keep getting: "The name 'Session' does not exist in the class or namespace 'xyz xyz xyz'" and "The type or namespace name 'Page' could not be found (are you missing a using directive or an...
7
4137
by: Shapiro | last post by:
I have a scenario where I log a resquest to a database table and update the request with a corresponding response including the response time. I am using an HttpModule to do this. My challenge is how to corelate the response to a corresponding request. I am looking for a sure proof threadsafe way to corelate a response to a coresponding request message. Two things that concerns me:-
6
5719
by: Steve | last post by:
Hi there, I'm trying to create a new website that will have a common aspx file serve as a template. I want all other pages to use this file and 'inject' their own content i.e. user controls, static html etc. The thing is that I don't actually want these other 'pages' to exist on disk (since I don't want to have to maintain multiple aspx pages - just the content). I basically want an XML file that defines the content 'page' path,...
1
3775
by: felippe | last post by:
Hi! I have got IIS 6.0 on Windows 2003 Server. I have installed HTTP handler (as simple reverse-proxy) - code below. I created virtual category with this dll and Wilcard application mapping set to aspnet_isapi.dll Now everything works fine, but sometimes IIS stops working and return 'Error in /catalog Application. Request timeout...' And than i must restart IIS (at least application pools).
3
12050
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. (machine.config) ---> System.Security.SecurityException: Request for the permission of type
2
5888
by: fredd00 | last post by:
Hi, i'm trying to use lazy loading with Linq to sql and related objects seems like you can only call the child object if the context is still open, this is not real lazy loading. here is my actual implementation my class product has a categories collection (using a one-to-many relation in .dbml)
5
2935
by: DR | last post by:
Why is its substantialy slower to load 50GB of gzipped file (20GB gzipped file) then loading 50GB unzipped data? im using System.IO.Compression.GZipStream and its not maxing out the cpu while loading the gzip data! Im using the default buffer of the stream that i open on the 20GB gzipped file and pass it into the GZipStream ctor. then System.IO.Compression.GZipStream takes an hour! when just loading 50GB file of data takes a few minutes!
0
8344
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
8857
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...
0
8764
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...
0
7367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
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
5654
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
4180
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
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
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.