Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > output

Reply
Thread Tools

output

 
 
H.S. Art
Guest
Posts: n/a
 
      06-27-2003
Hi folks,

I have a sript that runs very well. I do my output to the python shell
with the print command. That works well, too.
print 'Error occured ' + str(i+1)

No I want to have my output into a textctrl frame in a window. I start
my script by pushing a button in my window. It starts fine but I can't
see any output. For test purposes I added the following code to the
event handler of the button:
self.textCtrl1.WriteText('TEST\n')
This produces output to my text ctrl window. So I replaced all 'print'
commands in my script with 'self.textCtrl1.WriteText ...' Unfortunately
it still doesn't work. I don't get any output from my script. I always
get an error saying self is unknown. That's why I replaced it with the
name of the file of the window and so on and so on. Nothing worked. Can
you help me telling me how I have to write my code to get an output?

Thank you very much.
Henry

 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      06-27-2003
H.S. Art wrote:

> I have a sript that runs very well. I do my output to the python shell
> with the print command. That works well, too.
> print 'Error occured ' + str(i+1)
>
> No I want to have my output into a textctrl frame in a window. I start
> my script by pushing a button in my window. It starts fine but I can't
> see any output. For test purposes I added the following code to the
> event handler of the button:
>
> self.textCtrl1.WriteText('TEST\n')
>
> This produces output to my text ctrl window. So I replaced all 'print'
> commands in my script with 'self.textCtrl1.WriteText ...'


someone else will have to sort the variable scoping issues for you [1],
but in the meantime, you could try the following little trick.

1) at the top of your program, import the "sys" module:

import sys

2) in the event handler, add the following redirection code:

# redirect output to my window
class redirect:
def __init__(self, window):
self.write = window.WriteText
sys.stdout = redirect(self.textCtrl1)

</F>

1) the following links might be somewhat helpful:

http://www.python.org/doc/current/tu...00000000000000
http://www.python.org/doc/current/ref/naming.html (technical)




 
Reply With Quote
 
 
 
 
H.S. Art
Guest
Posts: n/a
 
      06-29-2003
Thank you for your answer!
That "little" trick works perfect for me.



Fredrik Lundh wrote:

>H.S. Art wrote:
>
>
>
>>I have a sript that runs very well. I do my output to the python shell
>>with the print command. That works well, too.
>>print 'Error occured ' + str(i+1)
>>
>>No I want to have my output into a textctrl frame in a window. I start
>>my script by pushing a button in my window. It starts fine but I can't
>>see any output. For test purposes I added the following code to the
>>event handler of the button:
>>
>>self.textCtrl1.WriteText('TEST\n')
>>
>>This produces output to my text ctrl window. So I replaced all 'print'
>>commands in my script with 'self.textCtrl1.WriteText ...'
>>
>>

>
>someone else will have to sort the variable scoping issues for you [1],
>but in the meantime, you could try the following little trick.
>
>1) at the top of your program, import the "sys" module:
>
> import sys
>
>2) in the event handler, add the following redirection code:
>
> # redirect output to my window
> class redirect:
> def __init__(self, window):
> self.write = window.WriteText
> sys.stdout = redirect(self.textCtrl1)
>
></F>
>
>1) the following links might be somewhat helpful:
>
>http://www.python.org/doc/current/tu...00000000000000
>http://www.python.org/doc/current/ref/naming.html (technical)
>
>
>
>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange problem - page output contains output from another request Paul ASP .Net 1 04-10-2007 03:41 PM
parse output screen ok but cant get desired output new file! chuck amadi Python 1 06-23-2004 02:16 PM
Sony Precision Cinema Progressive Output vs Component 480p Output Otto Pylot DVD Video 1 04-18-2004 09:49 PM
Is Fuji S3000 3.2m/pixel output, or 6 m/pixel interpolated output? Peter H Digital Photography 43 12-04-2003 02:35 PM
Output / Debug window output bug? John Bentley ASP .Net 0 09-10-2003 07:38 AM



Advertisments