daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /
  2. ├main.py
  3. └hoge
  4.   ├huga.py
  5.   └piyo.py
  6.    
  7. def execute():
  8.   print('huga_execute')
  9.    
  10. def execute():
  11.   print('piyo_execute')
  12.    
  13. import hoge.huga # importでhugaやpiyoは記載しない、
  14. import hoge.piyo
  15.  
  16. hoge.huga.execute() # これらを実行したい
  17. hoge.piyo.execute()
  18.    
  19. list = getModule('hoge') # ['huga', 'piyo']
  20. for m in list:
  21.   m.execute()
  22.    
  23. import sys, inspect
  24. for name, obj in inspect.getmembers(sys.modules['hoge']):
  25.     if inspect.ismodule(obj):
  26.         obj.execute()
  27.    
  28. import os
  29. import importlib
  30.  
  31. path = "./hoge"
  32.  
  33. files = os.listdir(path)
  34. modlist = [f for f in files if os.path.isfile(os.path.join(path, f))]
  35. print(modlist)
  36.  
  37. # ココにmodlistから拡張子を除去したり、.py以外を弾いたリストに加工する処理
  38.  
  39. for funcname in modlist:
  40.     plugmod = importlib.import_module("hoge."+funcname)
  41.     ret = plugmod.execute()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top