我的 argparser 变得很长。我想将它移到一个单独的文件中以保持我的主脚本干净。现在我有:
主要.py
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--test',
default=0.1,
type=float,
help='test')
# Many more arguments
args = parser.parse_args()
# My main code
print("Argument in my code:{}".format(args.test))
...
Run Code Online (Sandbox Code Playgroud)
有没有办法将其变成两个文件以保持我的主文件干净?
主要.py
import parsing_file
# My main code
print("Argument in my code:{}".format(args.test))
Run Code Online (Sandbox Code Playgroud)
解析文件.py
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--test',
default=0.1,
type=float,
help='test')
# Many more arguments
args = parser.parse_args()
Run Code Online (Sandbox Code Playgroud)