Isn't there a better way?

Dave Hansen iddw at hotmail.com
Sat Jul 22 15:58:26 EDT 2006


On 21 Jul 2006 07:51:15 -0700 in comp.lang.python, "T"
<ty.2006 at yahoo.com> wrote:

>
>I am using an optparse to get command line options, and then pass them
>to an instance of another class:
>
>
>
># Class that uses optparse.OptionParser
>foo = Parse_Option()
>
># Class that does the real work
>bar = Processor()
>
>bar.index = foo.options.index
>bar.output  = foo.options.output
>bar.run()


How about

   class Processor(whatever):
      ...
      def __init__(self,whatever_else):
      ...
      self.op = Parse_Option()

   ...
   bar = Processor()
   bar.run()

This would even let you do some preliminary option processing during
object initialization.

Regards,

   
                                        -=Dave

-- 
Change is inevitable, progress is not.



More information about the Python-list mailing list