[Tutor] How does this work?
Kent Johnson
kent37 at tds.net
Wed Feb 7 20:02:47 CET 2007
Tony Cappellini wrote:
>> You should be able to make the logging module work with you, it is very
>> flexible. You should hook into the logging module. Write a custom
>> handler that pushes log methods into your GUI. Add the handler to the
>> root logger.
>
> The cmd line app already uses the logging module- this is where the
> problem started.
>
> At the moment- due to the author's implementation, I can't pass in
> anything to modify ho the logger gets initialized. I have been
> thinking about asking him to let me pass in an instance of the logger
> to his main(), once I understand how to get the output from the logger
> into a string variable
>
>
>> Right, but the stand-alone stuff can be wrapped with
>> if __name__=='__main__':
>
> It already is. The cmd line app was written like this since day 1.
> I am now importing it and calling his main() via the module import
> import targetapp
>
> targetapp.main([arg1, arg2]) or whatever
You are still calling his code at too high a level. See if you can get
him to write his main() something like this:
def main(argv=sys.argv):
options = parse_options(argv)
configure_logging()
do_the_work(options)
or do_the_work(**options)
or do_the_work(options[0], options[1])
or...
where options is a list or dict or whatever kind of container makes
sense to hold the options. Then your code does the initialization that
makes sense for you - including hooking up the logging module to the GUI
- and calls do_the_work().
>
>> leaving the part you care about available for import in the same module.
>
>> The logging configuration should be in the main code as well, then when
>> you import the module you can configure logging the way you want.
>
> I think the hooks for the logging need to be changed, so I can pass
> them in or call them.
>
> Ok- now I will ask him to make his app a class
That is not needed, he just needs to make it more fine-grained so it has
a real API into the functional part that is distinct from the packaging
as a command-line app.
More information about the Tutor
mailing list