vscode-jupyter
vscode-jupyter copied to clipboard
argparse fails in interactive window
This bug from over a year ago is still present. https://github.com/microsoft/vscode-jupyter/issues/1837
This issue has been closed and locked because a work around was suggested. However the work around only prevents the file from crashing, and doesn't actually solve the issue (i.e. if you deploy the file with the work around, it will ignore command line arguments! So this will not work. The bug is still present)
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--test', default='Hello')
args = parser.parse_args()
print(vars(args))
usage: ipykernel_launcher [-h] [--test TEST]
ipykernel_launcher: error: unrecognized arguments: --ip=127.0.0.1 --stdin=9013 --control=9011 --hb=9010 --Session.signature_scheme="hmac-sha256" --Session.key=b"3b5fb288-5b42-46ea-8b68-8dc34e8fb27a" --shell=9012 --transport="tcp" --iopub=9014 --f=C:\Users\memoa\AppData\Local\Temp\tmp-30472W3VxMHiZejQB.json
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
%tb
---------------------------------------------------------------------------
SystemExit Traceback (most recent call last)
c:\Users\memoa\Dropbox\research\py\__tests\vscode\testargs.py in
6 parser = argparse.ArgumentParser()
7 parser.add_argument('--test', default='Hello')
----> 8 args = parser.parse_args()
9 print(vars(args))
C:\tools\Anaconda3\lib\argparse.py in parse_args(self, args, namespace)
1769 if argv:
1770 msg = _('unrecognized arguments: %s')
-> 1771 self.error(msg % ' '.join(argv))
1772 return args
1773
C:\tools\Anaconda3\lib\argparse.py in error(self, message)
2519 self.print_usage(_sys.stderr)
2520 args = {'prog': self.prog, 'message': message}
-> 2521 self.exit(2, _('%(prog)s: error: %(message)s\n') % args)
C:\tools\Anaconda3\lib\argparse.py in exit(self, status, message)
2506 if message:
2507 self._print_message(message, _sys.stderr)
-> 2508 _sys.exit(status)
2509
2510 def error(self, message):
SystemExit: 2