How to output newline or carriage return with optparse

Tim Chase python.list at tim.thechases.com
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 (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





More information about the Python-list mailing list