Skip to content

Commit 837ae3f

Browse files
committed
Adding run_all_solutions.py
1 parent 68eaf39 commit 837ae3f

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

code/run_all_solutions.py

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

0 commit comments

Comments
 (0)