In Python, using argparse, is there any way to parse text containing a newline character given as a parameter?
I have this script:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('text', help='some text with newline')
args = parser.parse_args(["line1\nline2"])
print(args.text)
which prints as expected:
line1
line2
but if I give the argument at the command-line (after changing to args = parser.parse_args()
in the script above) it's not doing the same. For example:
$ ./newline2argparse.py "line1\nline2"
line1\nline2
Any ideas on this?