[SNIPPET]: clean emacs python shell output
Janko Hauser
jhauser at ifm.uni-kiel.de
Tue Mar 7 10:39:02 EST 2000
This small code helps in saving the great scientific results found by
accident in an interactive python shell within emacs (and removing all
the failures :-)
Only lightly tested
HTH, __Janko
#!/usr/bin/env python
"""
Convert the output of an emacs shell buffer to a usefull script.
Filter out lines which generated a traceback.
Copyright 2000 Janko Hauser jhauser at ifm.uni-kiel.de
"""
__version__ = "0.1"
__author__ = "Janko Hauser jhauser at ifm.uni-kiel.de"
import sys, string
def clean_comint(fname):
lines = open(fname, 'r').readlines()
nlines = []
buffer=''
for line in lines:
if line[:9] == 'Traceback' or string.find(line,'<stdin>') >= 0:
buffer=''
if buffer and buffer[:3] != '>>>': # Can happen after ctrl-c
nlines.append(buffer)
buffer=''
if line[:4] == '>>> ' or line[:4] == '... ':
buffer=line[4:-1]
return nlines
if __name__ == "__main__":
import sys, string
nl = clean_comint(sys.argv[1])
print string.join(nl,'\n')
More information about the Python-list
mailing list