Created
September 4, 2008 11:27
-
-
Save atifaziz/8754 to your computer and use it in GitHub Desktop.
Extracts Python script from an interactive session source
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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