Question about bytecode and yield

Robert Brewer fumanchu at amor.org
Sun Jul 18 16:27:07 EDT 2004


[Daniel Brodie]
> ...Is it possible to, at runtime, change the bytecode
> of a function so that to turn it into a generator
> from a normal, average, function?

[Tim Peters]
> No.

But perhaps Mr. Brodie would be satisfied with creating a new function
based on the old. Doesn't "compile-time" include new.code()?

[Daniel Brodie]
> Would just putting in a YIELD_VALUE (in a sane way, 
> obviously) work?

[Tim Peters]
> No.

Perhaps setting the CO_ flags appropriately when using new.code() would
be sufficient...? I've had good success tinkering with those myself
(just not with generators yet). No time to test my theory at the moment,
so I'm hoping someone can answer definitively.


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org



More information about the Python-list mailing list