diff options
author | Inada Naoki <songofacandy@gmail.com> | 2022-06-23 12:09:57 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-23 12:09:57 +0900 |
commit | 9877f4c6249ac7f374dc48beaf21ea2bf3ee6996 (patch) | |
tree | effea480b2dc3d7f87af00f3b8ee97c49f9e6a50 /Doc/library/argparse.rst | |
parent | 576dd901170af30fc50b0a7f07a388b38fd724a9 (diff) | |
download | cpython-git-9877f4c6249ac7f374dc48beaf21ea2bf3ee6996.tar.gz |
gh-85308: argparse: Use filesystem encoding for arguments file (GH-93277)
Diffstat (limited to 'Doc/library/argparse.rst')
-rw-r--r-- | Doc/library/argparse.rst | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 0e62e99d70..b2fa0b3c23 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -562,7 +562,7 @@ at the command line. If the ``fromfile_prefix_chars=`` argument is given to the specified characters will be treated as files, and will be replaced by the arguments they contain. For example:: - >>> with open('args.txt', 'w') as fp: + >>> with open('args.txt', 'w', encoding=sys.getfilesystemencoding()) as fp: ... fp.write('-f\nbar') >>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@') >>> parser.add_argument('-f') @@ -575,9 +575,18 @@ were in the same place as the original file referencing argument on the command line. So in the example above, the expression ``['-f', 'foo', '@args.txt']`` is considered equivalent to the expression ``['-f', 'foo', '-f', 'bar']``. +:class:`ArgumentParser` uses :term:`filesystem encoding and error handler` +to read the file containing arguments. + The ``fromfile_prefix_chars=`` argument defaults to ``None``, meaning that arguments will never be treated as file references. +.. versionchanged:: 3.12 + :class:`ArgumentParser` changed encoding and errors to read arguments files + from default (e.g. :func:`locale.getpreferredencoding(False)` and + ``"strict"``) to :term:`filesystem encoding and error handler`. + Arguments file should be encoded in UTF-8 instead of ANSI Codepage on Windows. + argument_default ^^^^^^^^^^^^^^^^ |