← Back to DAGDA | Support | Source: https://bugs.python.org/issue25231

➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Argparse module and escape sequence (special symbols) in argument value
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: Ondřej Profant, martin.panter
Priority: normal Keywords:

Created on 2015-09-25 11:53 by Ondřej Profant, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg251580 - (view) Author: Ondřej Profant (Ondřej Profant) Date: 2015-09-25 11:53
I am trying to put tabulator '\t' into argument value. 

Minimal working example:

<code>
#!/usr/bin/env python3

import argparse

def main():
        parser = argparse.ArgumentParser()
        parser.add_argument('-f', '--foo', default="test", help="test")
        args = parser.parse_args()

        print("Argument foo is: " + args.foo + "|")
        print("Tabulator usage: |\t|")

if __name__ == '__main__':
        main()
</code>

My attempts:
./test.py -f \t
./test.py -f '\t'
./test.py -f "\t"

But this is not functional. Is there way to put special characters into argument?
~
msg251581 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-09-25 12:20
As far as I know “argparse” takes arguments straight from the command line without interpreting any escape sequences. Perhaps you should look up how to pass a literal tab on the command line, but this is nothing specific to do with Python. E.g. in the Bash shell the following might work:

$ echo $'a\tb'  # Bash specific syntax
a	b
$ echo "$(printf 'a\tb')"  # Any Posix shell
a	b
$ echo "a	b"  # Ctrl+V, Tab for literal tab to bypass completion
a	b
History
Date User Action Args
2022-04-11 14:58:21adminsetgithub: 69418
2015-09-25 12:20:04martin.pantersetstatus: open -> closed

nosy: + martin.panter
messages: + msg251581

resolution: third party
2015-09-25 11:53:57Ondřej Profantcreate