Python 3.x 我想为我的自定义类使用argparse/sys

Python 3.x 我想为我的自定义类使用argparse/sys,python-3.x,argparse,sys,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 ou

这个类是我的自定义类的一个简短版本,它读取一个.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-m main

我不知道该怎么做?

当您尝试上面写的内容时会发生什么?为什么需要/想要使用argparse?我也可以使用sys。但是我不知道如何从sys读取文本文件。argv[1]看起来您的
main
正确获取了文件名。现在必须将变量
input\u file
传递给文件读取器。从您的
MyClass
定义来看,这与读取文件的任务之间的关系并不明显。它应该以文件名作为参数吗?