RE: Question about bytecode and yield

Discussion in 'Python' started by Robert Brewer, Jul 18, 2004.

  1. [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
    Robert Brewer, Jul 18, 2004
    #1
    1. Advertising

  2. "Robert Brewer" <> writes:

    > [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.


    I didn't manage to divine exactly what Daniel was after, but using
    new.code() is almost certainly part of the solution...

    Cheers,
    mwh

    --
    "Well, the old ones go Mmmmmbbbbzzzzttteeeeeep as they start up and
    the new ones go whupwhupwhupwhooopwhooooopwhooooooommmmmmmmmm."
    -- Graham Reed explains subway engines on asr
    Michael Hudson, Jul 20, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Brodie

    Question about bytecode and yield

    Daniel Brodie, Jul 18, 2004, in forum: Python
    Replies:
    1
    Views:
    308
    Tim Peters
    Jul 18, 2004
  2. cat_dog_ass
    Replies:
    26
    Views:
    664
  3. Replies:
    1
    Views:
    317
    Gabriel Genellina
    Apr 22, 2008
  4. Markus
    Replies:
    1
    Views:
    191
    Mark Hubbart
    Sep 27, 2004
  5. Michael Edgar
    Replies:
    13
    Views:
    262
    Brian Candler
    Apr 21, 2011
Loading...

Share This Page