Re: Isn't there a better way?
Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Bruno Desthuilliers wrote: Lawrence D'Oliveiro a écrit : 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. I think I'm going to plonk you. And the rest of comp.lang.python has to know about this because ... ? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't there a better way?
In message [EMAIL PROTECTED], Steve Holden wrote: Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Bruno Desthuilliers wrote: Lawrence D'Oliveiro a écrit : 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. I think I'm going to plonk you. And the rest of comp.lang.python has to know about this because ... ? Some of them might be worth plonking as well? -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't there a better way?
Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Bruno Desthuilliers wrote: Lawrence D'Oliveiro a écrit : 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. I think I'm going to plonk you. Do what you want. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't there a better way?
Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Steve Holden wrote: Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Bruno Desthuilliers wrote: Lawrence D'Oliveiro a écrit : 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. I think I'm going to plonk you. And the rest of comp.lang.python has to know about this because ... ? Some of them might be worth plonking as well? Certainly. I suggest that you put in your killfile anyone not agreeing with you on any point, or having the bad idea to point out inexact or ambigous stuff in your posts. This will surely make this ng a very more friendly place to you - while perhaps not as useful. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't there a better way?
In message [EMAIL PROTECTED], Bruno Desthuilliers wrote: Lawrence D'Oliveiro a écrit : 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. I think I'm going to plonk you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't there a better way?
In message [EMAIL PROTECTED], 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. 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. -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't there a better way?
Lawrence D'Oliveiro a écrit : In message [EMAIL PROTECTED], 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. -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't there a better way?
On 21 Jul 2006 07:51:15 -0700 in comp.lang.python, T [EMAIL PROTECTED] 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. -- http://mail.python.org/mailman/listinfo/python-list
Isn't there a better way?
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??? -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't there a better way?
Le Fri, 21 Jul 2006 07:51:15 -0700, T a écrit : 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 know what both classes do, but can this be a solution ? class Processor(Parse_Option) self.index = self.option.index self.output = self.option.output def run(self): # code bar.run() Rony -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't there a better way?
I don't know what both classes do [snip] foo basically gets values for verbose (a True or False) and index (an integer) from command line options, using optparse.OptionParser.add_option() and optparse.OptionParser.parse_args() I would like bar to access the values of verbose and index. Is there another way? -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't there a better way?
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??? The standard way would be to have the Processor class's __init__() method take two arguments which it would then assign to the appropriate instance attributes. You could, of course, provide default values if you felt so inclined. Then you could just use bar = Processor(foo.options.index, foo.options.output) or something similar. That's better anyway, as it seems to make the coupling more explicit. What would you do if the index and output values were just stored in plain variables? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't there a better way?
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??? Not sure if this is better, but you can use OptionParser to set attributes on arbitrary objects, including your Processor instance: class Processor(object): ... def __init__(self): ... self.verbose = False ... self.index = 42 ... import optparse parser = optparse.OptionParser() parser.add_option(-v, --verbose, action=store_true) Option at 0x40294aac: -v/--verbose parser.add_option(-i, --index, type=int) Option at 0x40294a6c: -i/--index p = Processor() parser.parse_args(args=[-i75, -v], values=p) (__main__.Processor object at 0x40298e0c, []) p.verbose, p.index (True, 75) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't there a better way?
T wrote: I don't know what both classes do [snip] foo basically gets values for verbose (a True or False) and index (an integer) from command line options, using optparse.OptionParser.add_option() and optparse.OptionParser.parse_args() I would like bar to access the values of verbose and index. Is there another way? Sorry... I meant to say: foo basically gets values for index (an integer) and output (a string) -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't there a better way?
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??? What's wrong with: foo = Parse_Option() bar = Processor() bar.run(foo.options.index, foo.options.output) -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't there a better way?
Peter Otten [EMAIL PROTECTED] writes: [...] Not sure if this is better, but you can use OptionParser to set attributes on arbitrary objects, including your Processor instance: [...] I'd guess it's not worth the mental overhead required when you discover the next argument no longer fits this scheme. Or the mess when you start lying to yourself about what the interface of Processor should be, just so you can implement it like this. Still, better than just passing 'options' (from options, args = parser.parse_args()) to all your functions / classes, which... well, only makes sense if you get paid by the hour, and think that way, too ;-) John -- http://mail.python.org/mailman/listinfo/python-list