Nov 30 2009

Python Log Stdout to File

xiao

Python has the ability to alter its sys.stdout as to redirect its print commands to pretty much anything.

If, for instance, you want to print to both standard output and to a log file, you can create a class to handle the stdout like such:

class MyOutput():
    def __init__(self, logfile):
        self.stdout = sys.stdout
        self.log = open(logfile, 'w')
 
    def write(self, text):
        self.stdout.write(text)
        self.log.write(text)
        self.log.flush()
 
    def close(self):
        self.stdout.close()
        self.log.close()
 
sys.stdout = MyOutput("log.txt")
print "blah blah blah"

Continue reading


Sep 13 2009

Empty Home Directory in Windows Using Boot Camp 3.0

xiao

ls -a

Just got Snow Leopard and installed Boot Camp 3.0 on Windows? Boot Camp 3.0 is definitely a well welcomed update. The trackpad works much better now with 2 finger tap for secondary click, it finally works like in OS X. Even better, you can now access HFS+ without third party apps in Windows. Definitely nice for Windows 7 x64 users that MacDrive doesn’t even support. But one problem that seems to trouble people in the forums is that navigating to /Users/[yourname] in Windows shows an empty folder. You can’t access your music or pictures or anything from Windows.

One possibility is the presence of a .Xauthority file in your $HOME directory. Delete the file and you may access your home directory in Windows. Remember that running X11 will recreate the file. Delete it again. Continue reading


May 3 2009

PyQt Drag Images into List Widget for Thumbnail List

xiao

This simple tutorial shows how you can create a program with Python and Qt to allow for image files from Explorer/Finder/Nautilus to be dropped in a list widget and create list items with thumbnails

droppedthumbnails

First we subclass a QListWidget to handle events
Continue reading