Skip to content

Instantly share code, notes, and snippets.

@atifaziz
Created September 4, 2008 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atifaziz/8754 to your computer and use it in GitHub Desktop.
Save atifaziz/8754 to your computer and use it in GitHub Desktop.
Extracts Python script from an interactive session source
import sys, re
def main(args):
input = sys.stdin.read()
# Mac and Windows line endings to *nix
lines = input.replace('\r\n', '\r').replace('\r', '\n').split('\n')
exp = re.compile(r'(?:(?:\>|\.){3})\s(.+)')
print '\n'.join(
[match.group(1) for match in [
exp.search(line) for line in lines] if match])
if __name__ == '__main__':
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment