Thomas Nabelek <[email protected]> added the comment:
While overloading convert_arg_line_to_args may work, I think that @file reading
is kind of the odd ball out in not recognizing '#' as the beginning of a
comment.
Besides, I'm not sure that overloading just convert_arg_line_to_args is
sufficient. Here is what I have:
import argparse
import re
class ArgumentParserCustom(argparse.ArgumentParser):
def convert_arg_line_to_args(self, arg_line):
if re.match(r'(\s+)?#', arg_line): # Look for any number of whitespace
characters up to a `#` character
return ['']
else:
return [arg_line]
If I return [''], I get:
"error: unrecognized arguments:".
If I return [None], I get:
File
"C:\Users\tnabelek\AppData\Local\Programs\Python\Python38-32\lib\argparse.py",
line 1771, in parse_args
self.error(msg % ' '.join(argv))
TypeError: sequence item 0: expected str instance, NoneType found
Is there a better solution?
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue42677>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com