forked from AllenDowney/ThinkPython2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_all_solutions.py
74 lines (57 loc) · 2.27 KB
/
run_all_solutions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""This module contains a code example related to
Think Python, 2nd Edition
by Allen Downey
http://thinkpython2.com
Copyright 2015 Allen Downey
License: http://creativecommons.org/licenses/by/4.0/
"""
from __future__ import print_function, division
import os
def pipe(cmd):
"""Runs a command in a subprocess.
cmd: string Unix command
Returns (res, stat), the output of the subprocess and the exit status.
"""
# Note: os.popen is deprecated
# now, which means we are supposed to stop using it and start using
# the subprocess module. But for simple cases, I find
# subprocess more complicated than necessary. So I am going
# to keep using os.popen until they take it away.
fp = os.popen(cmd)
res = fp.read()
stat = fp.close()
assert stat is None
return res, stat
filenames = """
ackermann_memo.py grid.py PokerHand.py
ackermann.py has_duplicates.py PokerHandSoln.py
anagram_db.py header.py polygon.py
anagram_sets.py inlist.py reducible.py
analyze_book1.py interlock.py reverse_pair.py
analyze_book2.py invert_dict.py rotate_pairs.py
analyze_book3.py koch.py rotate.py
BadKangaroo.py letters.py sed.py
birthday.py Map.py spiral.py
Card.py markov.py structshape.py
cartalk1.py Markov.py Time1.py
cartalk2.py metathesis.py Time1_soln.py
cartalk3.py most_frequent.py Time2.py
do_four.py pace_calc.py Time2_soln.py
palindrome_soln.py typewriter.py
find_duplicates_copy.py pie.py unstable_sort.py
find_duplicates.py pi.py walk.py
flower.py Point1.py wordlist.py
GoodKangaroo.py Point1_soln.py zipf.py
"""
slow_ones = """
spiral.py typewriter.py pie.py
flower.py wordlist.py polygon.py
koch.py letters.py zipf.py
""".split()
for filename in filenames.split():
print(filename)
if filename in slow_ones:
print('Skipping')
continue
res, stat = pipe('python ' + filename)
print(stat)