create_init.py 670 B

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on 2018-08-28 17:38:43
  4. ---------
  5. @summary: 创建__init__.py
  6. ---------
  7. @author: Boris
  8. @email: boris_liu@foxmail.com
  9. """
  10. from feapder.utils.tools import dumps_json
  11. class CreateInit:
  12. def create(self):
  13. __all__ = []
  14. import os
  15. path = os.getcwd()
  16. for file in os.listdir(path):
  17. if file.endswith(".py") and not file.startswith("__init__"):
  18. model = file.split(".")[0]
  19. __all__.append(model)
  20. del os
  21. with open("__init__.py", "w", encoding="utf-8") as file:
  22. text = "__all__ = %s" % dumps_json(__all__)
  23. file.write(text)