2.2 open
Kragen Sitaker
kragen at pobox.com
Wed Mar 27 15:14:30 EST 2002
Greg Ewing <greg at cosc.canterbury.ac.nz> writes:
> > So the question now is, how do I tell if __import__ is the built in one
> > even if the import system is not fully initialized.
>
> You could compare its type with what you really
> should have been comparing it with in the
> first place:
>
> import types
> if type(__import__) == types.BuiltinFunctionType:
> ...
That'll still break in Python 4.6 when __import__ becomes an alias for
types.ModuleType, and again in Python 4.7 when __import__ becomes a
Python wrapper around some builtin functionality.
If you want to know if __import__ is the builtin __import__ because
you change it somewhere, you should put a flag somewhere that says
whether or not __import__ is overriden.
E.g. getattr(__import__('sys'), "myimportisinstalled").
Generically, if you want to know whether someone *else* has overridden
__import__, you are doing something immoral and should stop
immediately. But I well know that people have to do immoral things in
Python sometimes...
More information about the Python-list
mailing list