Isn't there a better way?

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sat Jul 22 14:32:23 EDT 2006


Lawrence D'Oliveiro a écrit :
> In message <1153493473.101466.290110 at m79g2000cwm.googlegroups.com>, T 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()
>>
>>
>>
>>This works, but it feels hokey or unnatural to "pass" data from one
>>class to another.  Isn't there a better way???
> 
> 
> I don't see the problem. 

The problem is setting bar attributes from the outside IMHO. Which is 
easily solved by passing the relevant stuff either at instanciation time 
or at call time.

> If you're calling a number of different routines in
> the Processor class, all accessing the same data, then it makes perfect
> sense to only pass it once.

Actually they are not "passed".



More information about the Python-list mailing list