Python code written in 1998, how to improve/change it?

Wolfgang Keller wolfgang.keller.nospam at
Tue Jan 24 20:13:34 CET 2006

On Fri, 20 Jan 2006 05:16:57 +0100, Peter Hansen wrote
(in article <mailman.821.1137730663.27775.python-list at>):

> I believe the more modern approach to this is to use generators in some 
> way, yield each other as the next state.  This way you avoid all almost 
> all the function call overhead (the part that takes significant time, 
> which is setting up the stack frame) and don't have to resort to 
> bytecode hacks for better performance.

Dumb question from a endless newbie scripting dilettant:

Do you have a reference to a cookbook example for this method?

Sidequestion: As I understand it, as a general rule generators are more 
efficient than functions in any case where the function is called several 
times, right? So basically if I want to write a long-running program in 
Python, it would make sense to code all functions that are likely to be 
called more than once as generators...



Wolfgang Keller

More information about the Python-list mailing list