Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66889 > unrolled thread
| Started by | Larry Hudson <orgnut@yahoo.com> |
|---|---|
| First post | 2014-02-22 02:57 -0800 |
| Last post | 2014-02-22 21:58 -0800 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
argparse question Larry Hudson <orgnut@yahoo.com> - 2014-02-22 02:57 -0800
Re: argparse question Peter Otten <__peter__@web.de> - 2014-02-22 12:58 +0100
Re: argparse question Larry Hudson <orgnut@yahoo.com> - 2014-02-22 21:58 -0800
| From | Larry Hudson <orgnut@yahoo.com> |
|---|---|
| Date | 2014-02-22 02:57 -0800 |
| Subject | argparse question |
| Message-ID | <y-ednQHk88Q3H5XOnZ2dnUVZ_judnZ2d@giganews.com> |
I have been reading the argparse section of the 3.3 docs, and running all the example code.
But in section 16.4.2.6. for the formatter_class, the second example in that section
illustrating RawDescriptionHelpFormatter, the example code is:
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
'''))
parser.print_help()
But trying to run this gives a NameError on the "description=" line, saying textwrap is not
defined. If I delete the "textwrap.dedent" (with or without also deleting the extra
parentheses) it will then run, but without the un-indenting it is trying to illustrate.
What is the proper way to enable the dedent() method here?
All the other examples have run correctly (that is, the one's I've tried -- I'm still reading).
Also, it should be obvious that while the "import argparse" line is not shown in the examples,
it IS in the code samples I've been running.
Using 3.3 under Linux (Mint 15).
-=- Larry -=-
[toc] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-02-22 12:58 +0100 |
| Message-ID | <mailman.7260.1393070405.18130.python-list@python.org> |
| In reply to | #66889 |
Larry Hudson wrote:
> I have been reading the argparse section of the 3.3 docs, and running all
> the example code.
>
> But in section 16.4.2.6. for the formatter_class, the second example in
> that section illustrating RawDescriptionHelpFormatter, the example code
> is:
>
> 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
> '''))
> parser.print_help()
>
> But trying to run this gives a NameError on the "description=" line,
> saying textwrap is not
> defined. If I delete the "textwrap.dedent" (with or without also deleting
> the extra parentheses) it will then run, but without the un-indenting it
> is trying to illustrate.
>
> What is the proper way to enable the dedent() method here?
textwrap is a module like argparse, and the example doesn't show
import argparse
either. Insert
import textwrap
at the beginning of your module and the code should run without error.
[toc] | [prev] | [next] | [standalone]
| From | Larry Hudson <orgnut@yahoo.com> |
|---|---|
| Date | 2014-02-22 21:58 -0800 |
| Message-ID | <iIGdnaqE8tKYE5TOnZ2dnUVZ_h2dnZ2d@giganews.com> |
| In reply to | #66893 |
On 02/22/2014 03:58 AM, Peter Otten wrote:
> Larry Hudson wrote:
>
>> I have been reading the argparse section of the 3.3 docs, and running all
>> the example code.
>>
>> But in section 16.4.2.6. for the formatter_class, the second example in
>> that section illustrating RawDescriptionHelpFormatter, the example code
>> is:
>>
>> 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
>> '''))
>> parser.print_help()
>>
>> But trying to run this gives a NameError on the "description=" line,
>> saying textwrap is not
>> defined. If I delete the "textwrap.dedent" (with or without also deleting
>> the extra parentheses) it will then run, but without the un-indenting it
>> is trying to illustrate.
>>
>> What is the proper way to enable the dedent() method here?
>
> textwrap is a module like argparse, and the example doesn't show
>
> import argparse
>
> either. Insert
>
> import textwrap
>
> at the beginning of your module and the code should run without error.
>
Thanx.
Guess I shoulda searched for textwrap or dedent in the docs. :-)
-=- Larry -=-
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web