How to output newline or carriage return with optparse

John john.m.roach at gmail.com
Thu Nov 8 21:07:10 CET 2007


On Nov 8, 12:40 pm, Tim Chase <python.l... at tim.thechases.com> wrote:
> > Thanks for the help Tim.  I just copied and pasted your code into a
> > file in my $PYTHONPATH (IndentedHelpFormatterWithNL.py), but I'm
> > getting the following error:
>
> >     class IndentedHelpFormatterWithNL(IndentedHelpFormatter):
> > NameError: name 'IndentedHelpFormatter' is not defined
>
> > I tried adding: from optparse imoport IndentedHelpFormatter into the
> > aforementioned file, but no luck again.  What am I missing???
>
> spelling "import" correctly? :)  Also, make sure that, if you've
> named your module "IndentedHelpFormatterWithNL.py" that created
> your parser with
>
>    parser = OptionParser(...
>      formatter=
>      IndentedHelpFormatterWithNL.IndentedHelpFormatterWithNL
>      )
>
> You'll also want to make sure that these two lines:
>
>    from optparse import IndentedHelpFormatter
>    import textwrap
>
> are at the top of the IndentedHelpFormatterWithNL.py file, not at
> the top of the file importing the IndentedHelpFormatter.
>
> -tkc

That seems to do the trick.  I'm sure there are quite a few people out
there who have run into this same problem-- I'm glad you're adding it
to the patches!




More information about the Python-list mailing list