annotate Demo/scripts/primes.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 4ba27d18dd92
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4573
73758db2f464 /usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents: 1269
diff changeset
1 #! /usr/bin/env python
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # Print prime numbers in a given range
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
56474
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
5 def primes(min, max):
56476
4ba27d18dd92 Fix 'primes 0 1'
Mark Dickinson <dickinsm@gmail.com>
parents: 56474
diff changeset
6 if max >= 2 >= min:
56474
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
7 print 2
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
8 primes = [2]
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
9 i = 3
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
10 while i <= max:
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
11 for p in primes:
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
12 if i % p == 0 or p*p > i:
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
13 break
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
14 if i % p != 0:
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
15 primes.append(i)
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
16 if i >= min:
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
17 print i
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
18 i += 2
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
19
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 def main():
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
21 import sys
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
22 min, max = 2, 0x7fffffff
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
23 if sys.argv[1:]:
56474
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
24 min = int(sys.argv[1])
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
25 if sys.argv[2:]:
56474
c105b98e649d Update primes script.
Georg Brandl <georg@python.org>
parents: 33456
diff changeset
26 max = int(sys.argv[2])
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
27 primes(min, max)
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
33456
487280cf71b9 Add 'if __name__ == "__main__":' to files already as a usable as a module.
Johannes Gijsbers <jlg@dds.nl>
parents: 32735
diff changeset
29 if __name__ == "__main__":
487280cf71b9 Add 'if __name__ == "__main__":' to files already as a usable as a module.
Johannes Gijsbers <jlg@dds.nl>
parents: 32735
diff changeset
30 main()