473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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.zipimporter("myziparchive.zip")
mod = importer.load_module("mymodule")
mod
<module 'mymodule' from 'myziparchive.zip\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_code("mymodule")
mod_code
<code object <moduleat 00B05260, file "myziparchive.zip
\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 774

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

Similar topics

0
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
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...
5
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...
7
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...
6
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,...
1
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...
3
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...
2
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.