Well, I'm using argparse module but have found that a multiline text as the version information won't be shown well. The result shows that the '\n' will be changed into space ' '.
Example:
import argparse
ver_text = 'This is the\nversion text!'
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--version', action='version', version=ver_text)
$ python test.py -v
Result:
This is the version text!
So this is the problem. I wonder how to handle it. Thanks very much!
If I use
ArgumentParser(formatter_class=RawTextHelpFormatter)
then it displays \n
import argparse
from argparse import RawTextHelpFormatter
ver_text = 'This is the\nversion text!'
parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter)
parser.add_argument('-v', '--version', action='version', version=ver_text)
parser.parse_args(['-v'])
But I don't know if other strings will work in correct way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With