J
Jeff Epler
I wrote this program, and when I ran it the Python process grew to 200+
megs, and I was forced to kill it:
# Program 1: code at module level
import itertools
j = 0
for i in itertools.count():
j = j + str(i).count("1")
if j == i: print i
I changed the program so that the work is done in a function, and the
Python process stays small, <3 megs.
# Program 2: code at function level
import itertools
def main():
j = 0
for i in itertools.count():
j = j + str(i).count("1")
if j == i: print i
main()
I thought I had a pretty good internal model of Python, but apparently
I don't, because I can't explain the difference in behavior between the
two programs.
Can someone enlighten me?
Jeff
PS Python 2.3.2, RedHat 9
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQFBYsjnJd01MZaTXX0RAmL9AKCIYx/kPCONKHMfbI6aIAu0x/RduQCfb9DJ
Gc0rS4BvfkcEY7cvO+4ds/I=
=Dcfr
-----END PGP SIGNATURE-----
megs, and I was forced to kill it:
# Program 1: code at module level
import itertools
j = 0
for i in itertools.count():
j = j + str(i).count("1")
if j == i: print i
I changed the program so that the work is done in a function, and the
Python process stays small, <3 megs.
# Program 2: code at function level
import itertools
def main():
j = 0
for i in itertools.count():
j = j + str(i).count("1")
if j == i: print i
main()
I thought I had a pretty good internal model of Python, but apparently
I don't, because I can't explain the difference in behavior between the
two programs.
Can someone enlighten me?
Jeff
PS Python 2.3.2, RedHat 9
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQFBYsjnJd01MZaTXX0RAmL9AKCIYx/kPCONKHMfbI6aIAu0x/RduQCfb9DJ
Gc0rS4BvfkcEY7cvO+4ds/I=
=Dcfr
-----END PGP SIGNATURE-----