You Are Here Home > Decorating Python’s sys.stdout
DirectorySync is a directory synchronizing and backup utility providing automated, real-time syncing and scheduled, configurable backups at an affordable price.

Decorating Python’s sys.stdout

Try this:

class stdoutflip:
 
    def __init__(self, sys):
        self.stdout = sys.stdout
        sys.stdout = self
 
    def write(self, txt):
        txt = list(txt)
        txt.reverse()
        self.stdout.write(''.join(txt))
 
 
class stdoutupper:
 
    def __init__(self, sys):
        self.stdout = sys.stdout
        sys.stdout = self
 
    def write(self, txt):
        self.stdout.write(txt.upper())

To test it do this:

out = stdoutupper(stdoutflip(sys))

Now try printing stuff:

print "Hello Python!"

:)

Decorating Python’s sys.stdout
Filed under: Fun,Programming,Python   Posted by: Codehead
Do you have any questions? ask here.




No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment