L0neGamer

python string importing

Jan 9th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. #Python 3.4.2
  2. import glob
  3. import os
  4. import sys
  5. import importlib
  6.  
  7. ModsRaw = glob.glob(os.path.join("mods", "*.py"))
  8. ModsShort = []
  9.  
  10. for i in ModsRaw:
  11.     ModsShort.append(i[5:-3])S
  12.  
  13. for i in ModsShort:
  14.     if i != "__init__":
  15.         imported_module = importlib.import_module("mods." + i)
  16.        
  17. modulenames = set(sys.modules)&set(globals())
  18. allmodules = [sys.modules[name] for name in modulenames]
  19. print(allmodules)
  20.  
  21. """
  22. What this code should do is find all the .py files in the subdirectory "mods", import them as modules, then display all the available modules. However, this doesn't seem to be working. What am I doing wrong?
  23. """
Advertisement
Add Comment
Please, Sign In to add comment