[Tutor] How does this work?
kent37 at tds.net
Wed Feb 7 17:34:53 CET 2007
Tony Cappellini wrote:
>> PS To import a file whose name is in a variable (string), see __import__().
> I've started doing the import instead of exec/eval , but the person
> who wrote the module being called, started using the logging module.
> Now I can't capture the output of the module I'm calling, and display
> it in a GUI. I was using popen() previously and that worked fine,
> until he started using logging
Rereading your past postings a little bit, what you really have is bad
If I understand you, you have a python cmdline app that does something
useful. You have users who aren't comfortable with the command line, so
you are writing a GUI wrapper that calls the cmdline app with popen().
A better approach is to turn the functional part of the cmdline app -
the code that does the real work - into an importable module. Then your
GUI app can import and use this module directly, instead of doing hacks
with popen() and stdout.
You don't even need a separate module for the cmdline app if it is
written correctly - the command-line-specific part can be in an main()
function that is only called if the module is run as main.
More information about the Tutor