__import__ .vs. sys.modules

François Pinard pinard at iro.umontreal.ca
Fri May 31 10:06:31 EDT 2002


Hello, people.

Yesterday, someone suggested on this list that:

        module = sys.modules[__name__]

should best be written:

        module = __import__(__name__)

This looked nice to me, at first.  However, if `__name__' contains dots,
only the first of the above writing works.  The second could be made to
work by splitting `__name__' at periods and doing more stunts after that,
but then, it becomes heavier and does not seem worth all the trouble.

So, maybe the first writing is best, after all.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list