Changes by Zachary Ware zachary.w...@gmail.com:
--
resolution: - not a bug
stage: - resolved
status: open - closed
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21416
___
Zachary Ware added the comment:
The type parameter of ArgumentParser is a callable that will be called with the
value of some member of sys.argv, it does *not* specify what the returned type
will be. You can just use os.fsencode as the type argument:
import os
import argparse
p =
paul j3 added the comment:
Two points to keep in mind:
'argparse' works with 'sys.argv[1:]'. If that does not contain what you want,
then you can pass your own 'argv' to 'parse_args'.
'type=bytes' means, call the builtin 'bytes' function with one of the argv
strings. If 'bytes' does not
paul j3 added the comment:
'invalid bytes value' is the error message generated by 'argparse'. The
underlying error (for a string like 'xxx') is:
print(bytes(sys.argv[1]))
TypeError: string argument without an encoding
You could use 'bytes' if you somehow supply the encoding, as in:
New submission from Derek Wilson:
If I create an argument parser like:
parser = argparse.ArgumentParser()
parser.add_argument('somebytes', type=bytes, help='i want some bytes')
parser.parse_args()
the parse_args() call will raise an exception printing usage info indicating
that an invalid