Extend file type

abcd codecraig at gmail.com
Tue Sep 26 11:14:22 EDT 2006


I have a class which extends 'file' ....

class MyFile(file):
    def __init__(self, fname, mode='r'):
        file.__init__(self, fname, mode)

    def write(self, str):
        print "writing a string"
        file.write(self, str)

    def writelines(self, lines):
        print "writing lines"
        file.writelines(self, lines)

I use this with subprocess....

f = MyFile('out.txt', 'w')
p = subprocess.Popen(cmd, stdout=f)

....and I can see that stuff goes into out.txt.....however, I never see
"writing a string" or "writing lines" from the class MyFile.

Any ideas what methods the stdout (and I guess stderr) of Popen objects
from subprocess call?

Any suggestions on how to find out?  I did try adding to MyFile....

def __call__(self, *args):
    print "calling:", args
    return file.__call__(self, *args)


but I never see that either.

thanks




More information about the Python-list mailing list