if option == 'help':
help()
还需要一种以相同方式显示库存的方法,这将是一个字典
但如果有人知道,我会更喜欢这种方式。
答案 0 :(得分:1)
通常,您会将类似的内容放在单独的文件中,并在需要时将其导入。以下是项目目录结构的外观:
# /home/your_user_name/PROJECT_DIR
# PROJECT_DIR/setup.py
# PROJECT_DIR/README.md
# PROJECT_DIR/your_app
# PROJECT_DIR/your_app/__init__.py # mark this folder as a python package named your_app
# PROJECT_DIR/your_app/main.py # your main codes
# PROJECT_DIR/your_app/utils.py # put stuff like help in here
所以在utils.py中:
def help():
ret = "calculating stuff to return"
return ret
在main.py中:
from your_app import utils
def run():
if option == 'help':
utils.help()
if __name__ == "__main__":
run()
希望有所帮助!