How to output newline or carriage return with optparse

Tim Chase python.list at
Thu Nov 8 18:40:55 CET 2007

> Thanks for the help Tim.  I just copied and pasted your code into a
> file in my $PYTHONPATH (, 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 "" that created 
your parser with

   parser = OptionParser(...

You'll also want to make sure that these two lines:

   from optparse import IndentedHelpFormatter
   import textwrap

are at the top of the file, not at 
the top of the file importing the IndentedHelpFormatter.


More information about the Python-list mailing list