[Python-Dev] New and Improved Import Hooks
Wiktor Sadowski
Wiktor Sadowski" <art@wiktorsadowski.com
Thu, 5 Dec 2002 00:24:31 +0100
This is a multi-part message in MIME format.
------=_NextPart_000_07AE_01C29BF4.AE00AAC0
Content-Type: text/plain;
charset="windows-1250"
Content-Transfer-Encoding: quoted-printable
>Should be "importing_module_from_dlls".
>I still don't understand. Is that some feature of Python?
Under Windows you can put a Module.pyd into Python/DLLs directory and:
import Module
>>If you mean "one .pyd file is one Python module", then this approach
>>won't work for .zip files:People want many .py modules in a single
.zip
>>file.
>It will work if handled by the zip importer.
>How will the zip importer know what zipfile to read?
>If I have "python23.zip", and do
>import httplib
>what mechanism will extract httplib.py from python23.zip?
As I said: a virtual directory-tree could be built for all zip files in=20
ARCHIVES directory:
ZipArchives:
ZipArchives/python23.zip:
ZipArchives/python23.zip/Lib:
ZipArchives/python23.zip/Lib/httplib.pyc
ZipArchives/another.zip:=20
ZipArchives/another.zip/another_directory:
=
ZipArchives/another.zip/another_directory/another_module.pyc =20
> from MyArchive_with_many_modules import MyModule
>So you could only zip entire packages?=20
No.
"from MyArchive import MyModule"
would be resolved by zip importer as:
if there is MyModule in MyArchive.zip then then import MyModule
(means extract and import)
and
import Module:
if Module.zip contains Module import Module
Wiktor
------=_NextPart_000_07AE_01C29BF4.AE00AAC0
Content-Type: text/html;
charset="windows-1250"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1250">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>>Should be "importing_module_from_dlls".<BR><BR>>I still =
don't=20
understand. Is that some feature of Python?</DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV>Under Windows you can put a Module.pyd into Python/DLLs directory=20
and:</DIV>
<DIV><FONT face=3DArial size=3D2><FONT face=3D"Times New Roman" =
size=3D3>import=20
Module</FONT></DIV>
<DIV><BR><FONT face=3D"Times New Roman" size=3D3>>>If you mean =
"one .pyd file=20
is one Python module", then this approach<BR>>>won't work for .zip =
files:People want many .py modules in a=20
single<BR>.zip<BR>>>file.<BR><BR>>It will work if handled by =
the zip=20
importer.<BR><BR>>How will the zip importer know what zipfile to=20
read?<BR><BR>>If I have "python23.zip", and do<BR><BR>>import=20
httplib<BR><BR>>what mechanism will extract httplib.py from=20
python23.zip?</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3></FONT> </DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3>As I said: a virtual=20
directory-tree could be built for all zip files in </FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3>ARCHIVES =
directory:</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3></FONT> </DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3>ZipArchives:</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3> =20
ZipArchives/python23.zip:</FONT></DIV>
<DIV><FONT face=3D"Times New Roman"=20
size=3D3> &nbs=
p; =20
ZipArchives/python23.zip/Lib:</FONT></DIV>
<DIV><FONT face=3D"Times New Roman"=20
size=3D3> &nbs=
p; =20
ZipArchives/python23.zip/Lib/httplib.pyc</FONT></DIV>
<DIV><FONT face=3D"Times New Roman"=20
size=3D3> ZipArchives/another.zip: </FONT></DIV>
<DIV><FONT face=3D"Times New Roman"=20
size=3D3> &nbs=
p; =20
ZipArchives/another.zip/another_directory:</FONT></DIV>
<DIV><FONT face=3D"Times New Roman"=20
size=3D3> &nbs=
p; =20
ZipArchives/another.zip/another_directory/another_module.pyc &=
nbsp; =20
</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3></FONT> </DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3>> from =
MyArchive_with_many_modules=20
import MyModule<BR><BR>>So you could only zip entire packages? =
</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3>No.</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3>"from MyArchive import=20
MyModule"</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3>would be resolved by zip =
importer=20
as:</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3>if there is MyModule in =
MyArchive.zip=20
then then import MyModule</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3>(means extract and =
import)</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3></FONT> </DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3>and</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3>import Module:</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3>if Module.zip contains =
Module import=20
Module</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D3></FONT> </DIV>
<DIV><FONT face=3D"Times New Roman"=20
size=3D3>Wiktor</FONT><BR></DIV></FONT></BODY></HTML>
------=_NextPart_000_07AE_01C29BF4.AE00AAC0--