Opened 15 years ago

Closed 15 years ago

#225 closed enhancement (wontfix)

Add functionality to Screen_catcher to print to screen and save

Reported by: nick Owned by: nick
Priority: low Milestone:
Component: Functionality and features Version:
Severity: trivial Keywords:


I think this should be fairly simply

Here is the class Screen catcher, And all i think is needed is a way to exit the writ e method without having the sys.stdout write something.

class Screen_Catcher:
    """this simply catches the screen output and stores it to file defined by
    start_screen_catcher (above)
    def __init__(self, filename, old_stuff=''):
        self.filename = filename
        if exists(self.filename)is True:
            print'Old existing file "%s" has been deleted' %(self.filename)
    def write(self, stuff):
        fid = open(self.filename, 'a')
        print_to_screen = True
        if print_to_screen: 
            if old_stuff==stuff:
                return #somehow exit write without printing anything
                print stuff
        print 'old_stuff',old_stuff,'stuff',stuff
        print 'old_stuff1',old_stuff,'stuff1',stuff

I have tried to implement the following case: If the print_to_screen is True, print the statement but stop sys.stdout printing out the results again which leads to an infinite loop.

I tried using a test with old_stuff==stuff but i think the solution lies in exitting Screen_catcher Write() without printing anything... "return" doesn't work but is there something like return but works at a different level... if that makes any sense...

Or explore a new way to pipe the print out away for sys.stdout to some other screen output

Change History (2)

comment:1 Changed 15 years ago by nick

This is not as simple as I first thought. Mainly due to the screen_catcher object replacing sys.stdout and if screen_catcher writes anything it ends in a infinite loop as sys.stdout is called which is actually screen_catcher.... if there was a way to set and unset sys.stdout with every write() called, you might avoid this... or maybe the below code could be useful.... or not

_CAPTURE = StringIO.StringIO() _FLAG = True # start capturing

def printf(obj):

global _CAPTURE, _FLAG if _FLAG:

where = _CAPTURE


where = sys.stdout

print >>where, obj

comment:2 Changed 15 years ago by nick

  • Resolution set to wontfix
  • Status changed from new to closed

This is being closed due the very low priority and my research into it suggested it will be tricky to implement

Note: See TracTickets for help on using tickets.