Entry
Clean emacs Python shell output
Jul 5th, 2000 10:03
Nathan Wallace, Hans Nowak, Snippet 387, Janko Hauser
"""
Packages: miscellaneous
"""
"""
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@ifm.uni-kiel.de
"""
__version__ = "0.1"
__author__ = "Janko Hauser jhauser@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')