[Patches] [ python-Patches-870286 ] make Demo/scripts/primes.py
usable as a module
SourceForge.net
noreply at sourceforge.net
Sat Jan 17 09:58:19 EST 2004
Patches item #870286, was opened at 2004-01-04 10:18
Message generated for change (Comment added) made by gerrit
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=870286&group_id=5470
Category: Demos and tools
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Gerrit Holl (gerrit)
Assigned to: Nobody/Anonymous (nobody)
Summary: make Demo/scripts/primes.py usable as a module
Initial Comment:
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.
----------------------------------------------------------------------
>Comment By: Gerrit Holl (gerrit)
Date: 2004-01-17 15:58
Message:
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).
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2004-01-12 00:44
Message:
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).
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=870286&group_id=5470
More information about the Patches
mailing list