[Patches] [ python-Patches-870286 ] make Demo/scripts/primes.py
usable as a module
SourceForge.net
noreply at sourceforge.net
Sat Sep 11 18:35:13 CEST 2004
Patches item #870286, was opened at 2004-01-04 10:18
Message generated for change (Comment added) made by jlgijsbers
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: Closed
>Resolution: Accepted
Priority: 5
Submitted By: Gerrit Holl (gerrit)
Assigned to: Johannes Gijsbers (jlgijsbers)
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: Johannes Gijsbers (jlgijsbers)
Date: 2004-09-11 18:35
Message:
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.
----------------------------------------------------------------------
Comment By: Johannes Gijsbers (jlgijsbers)
Date: 2004-08-18 17:58
Message:
Logged In: YES
user_id=469548
Gerrit, are you still interested in doing this? I'll just
check in this patch if not.
----------------------------------------------------------------------
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