Jach Feng wrote:
I have a script using the argparse module. I want to enter the string
"step\x0A" as one of its positional arguments. I expect this string has a
length of 5, but it gives 8. Obviously the escape character didn't function correctly.
How to do it?
That depends on the command-line shell you're calling your script from.
In bash, you can include a newline in a quoted string:
./your_script 'step
'
(the closing quote is on the next line)
Or if you want to do it on a single line (or use other escape
sequences), you can use e.g.:
./your_script $'step\x0a'
(dollar sign before a single-quoted string which contains escape sequences)
--
Mark.
--
https://mail.python.org/mailman/listinfo/python-list