python-3.x - 我想为我的自定义类使用 argparse/sys
问题描述
我的自定义类的简短版本,该类读取 .txt 文件并相应地返回输出。
class MyClass:
def some_method(self, arg1, arg2):
pass
我需要以这种形式给出解决方案,这是我的main.py
文件
def main():
input_file = sys.argv[1]
# parse the file and process the command
# print the output
if __name__ == "__main__":
main()
我需要从sys.argv[1]
.
CLI 应该像这样工作:
python -m main <absolute_path_to_input_file>
我无法弄清楚我应该如何解决这个问题?
解决方案
推荐阅读
- vue.js - Flask 静态提供的 vue-router 应用程序显示 Heroku 上自定义页面的 404
- reporting-services - SSRS 静态标题在其他页面中重复
- python - 使用 networkx 将加权有向图简化为 DAG
- .net - 如何在 .net core mvc 视图中缩小?
- python - 计算特定单词相邻单词出现的频率?
- python - 如何处理 json key herror
- r - 按数据框中变量的顺序排列线图
- python - Telegram API 消息错误,如何避免单词丢失
- java - Eclipse 插件打印超链接到控制台
- python - python - 进行左合并并得到错误的输出