import question

Philip Swartzleonard starx at pacbell.net
Tue May 14 06:00:08 EDT 2002


 || Tue 14 May 2002 02:36:15a:

> Hi all,
> 
> Is there a way to import all possible Python-modules in a module with 
> a single call (or some other small elegant solution)?

Not really. There's no 'import *', or god forbid 'from * import *' ;). 
You might be able to work something out by iterating over the files in 
sys.path and figureing out names to import from there. But, in any case, 
you'd be bloddy insane to do this. The modules that it would load vary 
from system to system for one thing -- and you'd have no idea what the 
hell would be in your namespace afterwards. But the most important 
reason i think would be that it would just kill your startup time for 
the script. Utterly. I mean, on my system here, doing such a thing would 
entail not just every single module in the standard library:

sys
os
curses
time
urllib
ftp
telnet
code
random
string
xml
dom
minidom
httplib
socket
threading
thread

and so on and so on and so on. this is just what cane to mind... i'm not 
sure of all the names. some of these probably have some load-time... but 
the most important is of course:

tkinter

on my system, there would also be:

PIL
wxPython
numeric
OpenGL.GL
OpenGL.GLU
openGL.GLUT

and some more stuff i forget. All of which, except maybe PIL and 
numberic, have huge startup times on their own. If you happen to have 
any of these around, just for some other scripts, you really don't want 
to pull them in.

Ok, ok... anyway. I have an idea that your problem might really be that 
you just have to import the same seven modules in every script you want 
to write 'cause they all do similar things. Well then, there IS a 
simpler solution to that. First make a file that has all of the modules 
that you need in it, just a bunch of 'import xyz' lines and nothin' 
else. Then, when you want that set, just do a 'from my_fave_modules 
import *' to get all the names you want. 

Sorry if i'm discohesive, i'm a little tired. =)

-- 
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com



More information about the Python-list mailing list