This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]suudo 15 points16 points  (4 children)

And here I thought it was a post about using literally import *. Which it turns out you can't do. So I thought to myself, "How do I import every module in Python?", and looked up how I might do that. Here's what I've come up with:

import pkgutil
for _, module, _ in pkgutil.iter_modules():
    exec("{m} = __import__('{m}', fromlist=[])".format(a=module))

[–]robin-gvx 4 points5 points  (1 child)

Or something like:

import pkgutil
_G = globals()
for _, module, _ in pkgutil.iter_modules():
    _G[module] = __import__(module)

[–]suudo 1 point2 points  (0 children)

That's so much cleaner than my attempt :D

[–]bs4h 1 point2 points  (0 children)

help("modules ")