I'm trying to make Argparse using unicode in both PY2 and PY3 preferably without complex constructs like if six.PY2:
or sys.version_info.major
. When it comes to using unicode for io operations or immediate string literals I know I have to use io/codecs or imports from __futute__
to resolve these issues. However not sure what is the best approach for argparse. Currently I'm using this code:
parser = argparse.ArgumentParser()
argv_enc = sys.getfilesystemencoding()
parser.add_argument('url', type=lambda s: bytearray(s,argv_enc).decode(argv_enc))
I think it's incorrect because bytearray tries to decode ASCII and I don't need this step at all. Instead I'd like to decode s
only if it's not already decoded.
Thanks in advance.