Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleanup, use __name__.

  • Loading branch information...
commit f5343dc8f788cd497f7c9bff082cfb9eea24664a 1 parent 431e732
@robertwb robertwb authored
View
7 binary_tree_cython.pyx
@@ -23,8 +23,7 @@ cdef long check_tree(Node t):
else:
return t.item + check_tree(t.left) - check_tree(t.right)
-
-def test(int n):
+def main(int n):
# By definition, trees can't have cycles. However, Python's garbage
# collector will do lots of wasteful tree traversals to try to collect
@@ -56,3 +55,7 @@ def test(int n):
iterations /= 4
print "long lived tree of depth %d\t check:" % max_depth, check_tree(long_lived_tree)
+
+if __name__ == '__main__':
+ import sys
+ main(int(sys.argv[1]))
View
19 fasta_cython.pyx
@@ -97,14 +97,17 @@ def randomFasta(table, int n):
buf[i] = cchars[k]
print line[:n % width]
+if __name__ == '__main__':
+ try:
+ n = int(sys.argv[1])
+ except IndexError:
+ n = 25000000
-n = 100 #int(sys.argv[1])
+ print '>ONE Homo sapiens alu'
+ repeatFasta(alu, n*2)
-print '>ONE Homo sapiens alu'
-repeatFasta(alu, n*2)
+ print '>TWO IUB ambiguity codes'
+ randomFasta(iub, n*3)
-print '>TWO IUB ambiguity codes'
-randomFasta(iub, n*3)
-
-print '>THREE Homo sapiens frequency'
-randomFasta(homosapiens, n*5)
+ print '>THREE Homo sapiens frequency'
+ randomFasta(homosapiens, n*5)
View
12 mandelbrot_cython.pyx
@@ -3,6 +3,7 @@
#
# contributed by Robert Bradshaw
+# Doesn't quite match the test output. Numerical noise?
import sys
@@ -47,5 +48,12 @@ def main(int size, outfile=sys.stdout):
write(line)
-#main()
-
+if __name__ == '__main__':
+ n = 16000
+ out = sys.stdout
+ try:
+ n = int(sys.argv[1])
+ file = open(sys.argv[2])
+ except IndexError:
+ pass
+ main(n, out)
View
10 nbody.pyx
@@ -139,12 +139,16 @@ cdef Planet neptune = Planet(
5.15138902046611451e-05 * solar_mass)
-def main(n=50000000):
- if n is None:
- n = int(sys.argv[1])
+cdef main(n):
cdef Planet* bodies = [sun, jupiter, saturn, uranus, neptune]
offset_momentum(bodies)
print "%.9f" % energy(bodies)
advance(bodies, 0.01, n)
print "%.9f" % energy(bodies)
+if __name__ == '__main__':
+ try:
+ n = int(sys.argv[1])
+ except IndexError:
+ n = 50000000
+ main(n)
View
9 pidigits_cython.pyx
@@ -77,5 +77,10 @@ def pidigits(unsigned int n):
print "%s%s\t:%s" % (line[:m+1], ' ' * (10-m), n)
-def main():
- pidigits(1000)
+if __name__ == '__main__':
+ import sys
+ try:
+ n = int(sys.argv[1])
+ except IndexError:
+ n = 2500
+ pidigits(n)
Please sign in to comment.
Something went wrong with that request. Please try again.