would be nice: import from archive

Jorge Godoy godoy at ieee.org
Fri Aug 27 17:55:33 EDT 2004


aleaxit at yahoo.com (Alex Martelli) writes:

> Dan Perl <dperl at rogers.com> wrote:
>    ...
>> 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. ;-)
>
> If somebody submits a good recipe about it, I'll be overjoyed to add it
> (not sure what chapter -- 'files'?  'system administration'?  'programs
> about programs'? -- ah well, I'll find a spot!-).
>
> In the 2nd Edition of the _Nutshell_, when THAT comes (don't hold your
> breath!-), I'll write it up just like I will for all the new delights
> since 2.2 -- but for the Cookbook I'm supposed to use recipes that
> people do submit to the online cookbook site... OK, I and my co-editors
> _do_ perform a lot of editing and merging, and occasionally do add a
> recipe or three, but mostly it IS the book you all have written, with
> over a hundred authors covering the subjects THEY think matter...

It would be great to have one example with more than one file.

>From the discussion I got curious and tested it here and -- since
Python's so efficient I wasn't surprised that -- it worked. 



$ cat test.py
def test():
        print "Test from file 1"

$ cat test2.py
def test():
        print "Test from file 2"


>>> import sys
>>> sys.path.append('test.zip')
>>> import test
>>> import test2
>>> test.test()
Test from file 1
>>> test2.test()
Test from file 2
>>>


I also noticed that there was no '.pyc' created for that import, as is
usually done for uncompressed modules.  



Be seeing you,
-- 
Godoy.     <godoy at ieee.org>



More information about the Python-list mailing list