This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: make Demo/scripts/primes.py usable as a module
Type: Stage:
Components: Demos and Tools Versions: Python 2.4
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: jlgijsbers Nosy List: gerrit, jlgijsbers, rhettinger
Priority: normal Keywords: patch

Created on 2004-01-04 09:18 by gerrit, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
primes.diff gerrit, 2004-01-04 09:18 patch created with 'cvs diff -u'
Messages (5)
msg45109 - (view) Author: Gerrit Holl (gerrit) Date: 2004-01-04 09:18
I wanted to find all primes between 1985 and 2005, and
found out that Demo/scripts/primes.py is not usable as
a module, because it unconditionally executes main().
This patch adds a 'if __name__ == "__main__"' block
around the execution of the main() function, so that
one can simply import primes and use
primes.primes(1985, 2005) in order to achieve what I
wanted to achieve.
msg45110 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-01-11 23:44
Logged In: YES 
user_id=80475

If you're going to improve this one, consider going all the way.

* Modernize the code -- the current version reads like Cobol
* Stop building the sieve after sqrt(MAX) entries have been
found.  Possibly use islice() to check only the relevant
entries in the primes table.
* Change the API to:  prime x [n]  which finds the first n
(default 1) primes larger than x.  prime(10,3) --> [11, 13, 17]
* If x is large, switch to a modern primality testing
algorithm so that arbitrarily large primes can be found
(perhaps for RSA purposes or some such).
msg45111 - (view) Author: Gerrit Holl (gerrit) Date: 2004-01-17 14:58
Logged In: YES 
user_id=13298

Hm, I don't think I have enough mathematical knowledge to go
'all the way', although some of the suggestions are doable.
I'll have a look at it next week (week of Jan-26). 
msg45112 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-08-18 15:58
Logged In: YES 
user_id=469548

Gerrit, are you still interested in doing this? I'll just
check in this patch if not.
msg45113 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-09-11 16:35
Logged In: YES 
user_id=469548

Well, I just checked in this patch and added  'if __name__
== "__main__"' to a whole bunch of other modules too.
History
Date User Action Args
2022-04-11 14:56:02adminsetgithub: 39758
2004-01-04 09:18:52gerritcreate