Title: argparse formatter_class issue for RawDescriptionHelpFormatter
Type: resource usage Stage: resolved
Components: Documentation Versions: Python 2.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Mariatta, ckessler, docs@python, paul.j3
Priority: normal Keywords:

Created on 2018-07-20 20:34 by ckessler, last changed 2018-07-23 16:00 by paul.j3. This issue is now closed.

Messages (4)
msg322034 - (view) Author: Chris Kessler (ckessler) Date: 2018-07-20 20:34
In document

this will fail with NameError: global name 'textwrap' is not defiend

>>> parser = argparse.ArgumentParser(
...     prog='PROG',
...     formatter_class=argparse.RawDescriptionHelpFormatter,
...     description=textwrap.dedent('''\
...         Please do not mess up this text!
...         --------------------------------
...             I have indented it
...             exactly the way
...             I want it
...         '''))
msg322036 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2018-07-20 20:42
Thanks for the report.

To make it work, you'll have to import textwrap first.

We don't always add all the necessary imports in our code snippets and examples, and we don't need to start adding imports into code examples either. So I'm closing this issue.

Thanks again.
msg322037 - (view) Author: Chris Kessler (ckessler) Date: 2018-07-20 21:02
Thanks for the quick response!
I didnt see it anywhere in the documentation on that page so I assumed it was built in with argparse.
msg322228 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2018-07-23 16:00
argparse does import 'textwrap', but as '_textwrap', so it could be used with:


Importing your own is cleaner.
Date User Action Args
2018-07-23 16:00:05paul.j3setnosy: + paul.j3
messages: + msg322228
2018-07-20 21:02:39ckesslersetmessages: + msg322037
2018-07-20 20:42:30Mariattasetstatus: open -> closed

nosy: + Mariatta
messages: + msg322036

resolution: not a bug
stage: resolved
2018-07-20 20:34:50ckesslercreate