How to easily create python package, keeping the folder structure and files?

空扰寡人 提交于 2020-02-25 05:49:49

问题


I have a folder with structure like this (names are not real):

script0_1.py
script0_2.py
- folder1
  - folder1_1
    - script1_1_1.py
    - script1_1_2.py
  - folder1_2
    - script1_2_1.py
    - script1_2_2.py
- folder2
  - script2_1.py
- folder3
...

Important moment is that the structure can be changed, scripts added, etc. I want to create a package, to be able to run commands like this my_package.folder1.folder1_1.script1_1_1.some_func(), easily. I know a bit that I can create __init__.py in each folder, then import all function one by one, but maybe there is an easier way? Also, I'm interested, how to import all function in the folders or subfolders, but not by importing them in __init__.py one by one, for example if there is a function my_package.folder1.folder1_1.script1_1_1.some_func(), I can use simply my_package.some_func()

来源:https://stackoverflow.com/questions/60052928/how-to-easily-create-python-package-keeping-the-folder-structure-and-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!