Here is a python feature that I would like: to be able to import modules
from an archive like the jar files in Java. Maybe a regular tar file?
Maybe a python specific file type, let's call it a 'par' file?
It would be useful in packaging an python library. Sure, there's always the
python packages, but a single file instead of a whole directory tree would
be more convenient. I am particularly interested because I am working on a
framework/toolkit and I am using a configuration divided into several
modules. It would be nice to be able to save configurations (combinations
of several modules) into single archive files and then switch between
configurations by pointing to one such archive file.
I am quite new to python so I should ask first whether there is already
something like that, although I did a search already. Or maybe such a
feature has already been discussed somewhere? If this is an original idea,
how can I propose it for future releases?
Dan Perl
(yes, I'm Mr. Perl, but I'm using Python, after all Perl is not my middle
name, it's my last name) 43 2517
On Fri, 27 Aug 2004 17:06:06 GMT, Dan Perl <dp***@rogers.c om> wrote: Here is a python feature that I would like: to be able to import modules from an archive like the jar files in Java. Maybe a regular tar file? Maybe a python specific file type, let's call it a 'par' file?
Or a zip file, perhaps? See PEP-0273, which was implemented in Python 2.3.
(Hm. 273 isn't up-to-date. This is bad :-(
My bad. Right after posting the message I found the 'Index of Python
Enhancement Proposals (PEPs)'
and there is PEP 273, 'Import Modules from Zip Archives', submitted by
James C. Ahlstrom. Thank you, Jim! And there are even two implementations
already.
Dan
"Dan Perl" <dp***@rogers.c om> wrote in message
news:2S******** ***********@new s01.bloor.is.ne t.cable.rogers. com... Here is a python feature that I would like: to be able to import modules from an archive like the jar files in Java. Maybe a regular tar file? Maybe a python specific file type, let's call it a 'par' file?
It would be useful in packaging an python library. Sure, there's always
the python packages, but a single file instead of a whole directory tree would be more convenient. I am particularly interested because I am working on
a framework/toolkit and I am using a configuration divided into several modules. It would be nice to be able to save configurations (combinations of several modules) into single archive files and then switch between configurations by pointing to one such archive file.
I am quite new to python so I should ask first whether there is already something like that, although I did a search already. Or maybe such a feature has already been discussed somewhere? If this is an original
idea, how can I propose it for future releases?
Dan Perl (yes, I'm Mr. Perl, but I'm using Python, after all Perl is not my middle name, it's my last name)
Yes, I saw that after posting my initial message. Thanks though, Anthony!
Dan
"Anthony Baxter" <an***********@ gmail.com> wrote in message
news:ma******** *************** *************** @python.org... On Fri, 27 Aug 2004 17:06:06 GMT, Dan Perl <dp***@rogers.c om> wrote: Here is a python feature that I would like: to be able to import modules from an archive like the jar files in Java. Maybe a regular tar file? Maybe a python specific file type, let's call it a 'par' file?
Or a zip file, perhaps? See PEP-0273, which was implemented in Python 2.3.
(Hm. 273 isn't up-to-date. This is bad :-(
"Dan Perl" <dp***@rogers.c om> wrote in message
news:2S******** ***********@new s01.bloor.is.ne t.cable.rogers. com... Here is a python feature that I would like: to be able to import modules from an archive like the jar files in Java. Maybe a regular tar file?
[snip] I am quite new to python so I should ask first whether there is already something like that, although I did a search already. Or maybe such a feature has already been discussed somewhere? If this is an original
idea, how can I propose it for future releases?
Well, you can use .zip files http://www.python.org/doc/2.3.4/whatsnew/node5.html
HTH,
Sean
Dan Perl <dp***@rogers.c om> wrote: Here is a python feature that I would like: to be able to import modules from an archive like the jar files in Java. Maybe a regular tar file?
Python 2.3 lets you import modules from a zipfile. The zip format is
better than tar when you just need to get one file from it, which is why
java's jar files are also basically zipfiles.
I am quite new to python so I should ask first whether there is already something like that, although I did a search already. Or maybe such a feature has already been discussed somewhere? If this is an original idea, how can I propose it for future releases?
It's there already, and has been for over a year now;-).
Alex
On Fri, 27 Aug 2004 17:15:49 GMT, Dan Perl <dp***@rogers.c om> wrote: My bad. Right after posting the message I found the 'Index of Python Enhancement Proposals (PEPs)' and there is PEP 273, 'Import Modules from Zip Archives', submitted by James C. Ahlstrom. Thank you, Jim! And there are even two implementations already.
Note that the PEP is not up-to-date. zipimport "just works" in Python
2.3 and Python 2.4. In the following example, we use the -v flag to
show where imports are coming from.
bonanza% cat hello.py
def hello():
print 'hello world'
bonanza% zip hello.zip hello.py
adding: hello.py (deflated 8%)
bonanza% rm hello.py
bonanza% python2.4 -v
Python 2.4a2 (#3, Aug 24 2004, 01:25:51)
[GCC 3.4.0 20040613 (Red Hat Linux 3.4.0-5)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
... lots and lots of lines showing default imports snipped ... import hello
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named hello import sys sys.path.append ('hello.zip') import hello
# zipimport: found 1 names in hello.zip
dlopen("/usr/local/lib/python2.4/lib-dynload/zlib.so", 2);
import zlib # dynamically loaded from
/usr/local/lib/python2.4/lib-dynload/zlib.so
# zipimport: zlib available
import hello # loaded from Zip hello.zip/hello.py hello.hello()
hello world
At least on this box (linux) there's even a zip file on the default sys.path!
Anthony al*****@yahoo.c om (Alex Martelli) writes: Here is a python feature that I would like: to be able to import modules from an archive like the jar files in Java. Maybe a regular tar file?
Python 2.3 lets you import modules from a zipfile. The zip format is better than tar when you just need to get one file from it, which is why java's jar files are also basically zipfiles.
Jar files are -signed- zip files. Is there some reason to not do that
for Python?
I am using 2.3 and I tried importing from a zip file in a script of my own
and, yes, it works.
I never used the -v flag before but it's great for debugging some problems.
Thanks for mentioning it!
Dan
"Anthony Baxter" <an***********@ gmail.com> wrote in message
news:ma******** *************** *************** @python.org... Note that the PEP is not up-to-date. zipimport "just works" in Python 2.3 and Python 2.4. In the following example, we use the -v flag to show where imports are coming from.
----- Original Message -----
From: "Alex Martelli" <al*****@yahoo. com>
Newsgroups: comp.lang.pytho n
Sent: Friday, August 27, 2004 1:37 PM
Subject: Re: would be nice: import from archive Python 2.3 lets you import modules from a zipfile. The zip format is better than tar when you just need to get one file from it, which is why java's jar files are also basically zipfiles.
[...]
It's there already, and has been for over a year now;-).
Alex
Alright, alright! And given the fact that it was added only in 2.3, that
explains why I couldn't find any mention of the feature in 'Python
Cookbook', the 1st ed. I'm looking forward to seeing it mentioned in the
2nd ed. ;-)
Dan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Thomas Heller |
last post by:
I'm currently working on a new version of py2exe, which will require
Python 2.3 and later, because it uses the zipimport mechanism.
Since py2exe is a distutils extension, and since C compilers are
commonly available on most platforms except Windows, it would be fairly
easy to let py2exe generate a C source file installing this import hook,
and let distutils' C compiler build an executable file from this.
Would this be useful, or would...
|
by: fts2012 |
last post by:
follow the dive into python
-----------------------------------------------------------------
-----------------------------------------------------------------
I append the filepath of <<dive into python>>'s examples into
sys.path,but
-----------------------------------------------------------------
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
|
by: Gabriel Genellina |
last post by:
En Fri, 13 Jun 2008 22:38:24 -0300, Dan Yamins <dyamins@gmail.comescribió:
I don't get *why* do you want to remove the 'archive' attribute before reloading the module. Just reload it *without* using `del` previously.
When you reload a module, new definitions for existing names replace the old objects; new names are added; old names without a new value keep the previous value. (That is, objects are *replaced* and *added* but not...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |