Need guidelines to show results of a process

MRAB google at mrabarnett.plus.com
Thu Mar 19 20:35:45 EDT 2009


Vizcayno wrote:
> Hi:
> I wrote a Python program which, during execution, shows me messages on
> console indicating at every moment the time and steps being performed
> so I can have a 'log online' and guess remaining time for termination,
> I used many 'print' instructions to show those messages, i.e.  print
> "I am in step 4 at "+giveTime() .... print "I am in step 5 at
> "+giveTime(), etc.
> Now I need to execute the same program but from a GUI application. I
> must show the same messages but on a "text field".
> As you can guess, it implies the changing of my program or make a copy
> and replace the print instructions by   textField += "I am in step 4
> at "+giveTime() then textField += "I am in step 5 at "+giveTime(),
> etc.
> I wanted to do the next:
> if output == "GUI":
>     textField += "I am in step 4 at "+giveTime()
>     force_output()
> else:
>     print "I am in step 4 at "+giveTime()
> But it is not smart, elegant, clean ... isn't it?
> Any ideas please?
> Regards.
> 
At the very least you could put the reporting into a function:

     def report(message):
         if output == "GUI":
             textField += message
             force_output()
         else:
             print message

     ...
     report("I am in step 4 at " + giveTime())




More information about the Python-list mailing list