I have a script in which a very long argument of type str
is passed to a function:
parser = argparse.ArgumentParser(description='Auto-segments a text based on the TANGO algorithm (Rie Kubota Ando and Lillian Lee, "Mostly-Unsupervised Statistical Segmentation of Japanese Kanji Sequences" (Natural Language Engineering, 9(2):127-149, 2003)).')
I'd like to limit line length in this script to 79 chars, which means line breaking in the middle of the string in question. Simply wrapping at 79 yields something like this, which is syntactically ill-formed:
parser = argparse.ArgumentParser(description="Auto-segments a text based on
the TANGO algorithm (Rie Kubota Ando and Lillian Lee, 'Mostly-Unsupervis
ed Statistical Segmentation of Japanese Kanji Sequences' (Natural Langua
ge Engineering, 9(2):127-149, 2003)).")
PEP 8 has guidelines for breaking lines in various non-argument-string-internal locations, but is there a way to break the line in the middle of an argument string?
(Related but less important question: What is a sensible/conventional way to break natural language text mid-word inside a (python) script?)
Literal strings can appear next to each other, and will compile to a single string. Thus:
parser = argparse.ArgumentParser(description="Auto-segments a text based on "
"the TANGO algorithm (Rie Kubota Ando and Lillian Lee, 'Mostly-Unsupervised "
"Statistical Segmentation of Japanese Kanji Sequences' (Natural Language "
"Engineering, 9(2):127-149, 2003)).")
Adjust as desired to fit in 80.
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