我试图做this Gooey GUI tutorial:,但我确实无法通过他解析参数的第一段代码。我试过Spyder和Jupyter,在这个街区被困了一个小时:from argparse import ArgumentParser
parser = ArgumentParser(description='Create Quarterly Marketing Report')
parser.add_argument('data_directory',
action='store',
help="Source directory that contains Excel files")
parser.add_argument('output_directory',
action='store',
help="Output directory to save summary report")
parser.add_argument('cust_file',
action='store',
help='Customer Account Status File')
parser.add_argument('-d', help='Start date to include')
args = parser.parse_args()
我的错误:
^{pr2}$
完全回溯:---------------------------------------------------------------------------
SystemExit Traceback (most recent call last)
in
----> 1 args = parser.parse_args('')
~\Anaconda3\lib\argparse.py in parse_args(self, args, namespace)
1747 # =====================================
1748 def parse_args(self, args=None, namespace=None):
-> 1749 args, argv = self.parse_known_args(args, namespace)
1750 if argv:
1751 msg = _('unrecognized arguments: %s')
~\Anaconda3\lib\argparse.py in parse_known_args(self, args, namespace)
1779 # parse the arguments and exit if there are any errors
1780 try:
-> 1781 namespace, args = self._parse_known_args(args, namespace)
1782 if hasattr(namespace, _UNRECOGNIZED_ARGS_ATTR):
1783 args.extend(getattr(namespace, _UNRECOGNIZED_ARGS_ATTR))
~\Anaconda3\lib\argparse.py in _parse_known_args(self, arg_strings, namespace)
2014 if required_actions:
2015 self.error(_('the following arguments are required: %s') %
-> 2016 ', '.join(required_actions))
2017
2018 # make sure all required groups had one option present
~\Anaconda3\lib\argparse.py in error(self, message)
2499 self.print_usage(_sys.stderr)
2500 args = {'prog': self.prog, 'message': message}
-> 2501 self.exit(2, _('%(prog)s: error: %(message)s\n') % args)
~\Anaconda3\lib\argparse.py in exit(self, status, message)
2486 if message:
2487 self._print_message(message, _sys.stderr)
-> 2488 _sys.exit(status)
2489
2490 def error(self, message):
SystemExit: 2
我在堆栈溢出时检查了这个错误,但是建议的答案对我来说不起作用,或者没有足够详细地让我找出问题所在。在
我知道这应该在命令行中使用,但是有什么方法可以在Jupyter或Spyder中遵循上面的教程吗?在
编辑:不确定这是否有帮助,但sys.argv的输出:['C:\\Users\\s\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py',
'-f',
'C:\\Users\\s\\AppData\\Roaming\\jupyter\\runtime\\kernel-cc697613-14f5-4979-a353-6112886aba45.json']