首页 > 解决方案 > 我想为我的自定义类使用 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>

我无法弄清楚我应该如何解决这个问题?

标签: python-3.xargparsesys

解决方案


推荐阅读