views:

47

answers:

1

I would like to run a set of python commands from a file in the PDB debugger. Related to this, can I set up a file that is automatically run when PDB starts?

+1  A: 

make a subclass of pdb.Pdb and put a call to your extra stuff in the __init__

alternatively

pdb.Pdb() looks for a .pdbrc file, so you may be able to put your stuff in there

    # Read $HOME/.pdbrc and ./.pdbrc
    self.rcLines = []
    if 'HOME' in os.environ:
        envHome = os.environ['HOME']
        try:
            rcFile = open(os.path.join(envHome, ".pdbrc"))
        except IOError:
            pass
        else:
            for line in rcFile.readlines():
                self.rcLines.append(line)
            rcFile.close()
    try:
        rcFile = open(".pdbrc")
    except IOError:
        pass
    else:
        for line in rcFile.readlines():
            self.rcLines.append(line)
        rcFile.close()
gnibbler