__import__

Heiko Wundram heikowu at ceosg.de
Sat May 8 03:40:39 EDT 2004


Am Samstag, 8. Mai 2004 09:31 schrieb Coder Coder:
> Can someone help me with how to overload the __import__ function,
> so that I can call the old __import__ function and if it cannot find
> the library to be able to do something else.

You shouldn't overload a builtin (at least if you expect to be compatible with 
other programmers libraries), but rather do the following where you need it:

try:
	import <my-package>
except ImportError:
	<do something else>

Repeat after me: "Overloading a builtin is evil! Overloading a builtin is 
evil!"

HTH!

Heiko.




More information about the Python-list mailing list