RE: Cell objects and their values

Discussion in 'Python' started by Robert Brewer, Apr 22, 2004.

  1. Jeff Epler wrote:
    > This seems to work, but it's undocumented (specifically,
    > func_closure as
    > an argument to new.function is undocumented) and makes my tummy feel
    > funny when I think about it.
    >
    > >>> import new
    > >>> def cell_get(cell):

    > ... def f(): return cell
    > ... return new.function(f.func_code, {}, "f", (), (cell,))()
    > ...


    Rock. On.

    That is frickin' brilliant in at least three ways I never would have
    thought of. :) Thanks! Looking back over Raymond's bytecode hack in PEP
    329, I notice he also used func_closure as an arg to function(). In
    addition, he avoided importing the "new" module by just calling
    type(f)().

    Danke.


    Robert Brewer
    MIS
    Amor Ministries
     
    Robert Brewer, Apr 22, 2004
    #1
    1. Advertising

  2. "Robert Brewer" <> writes:

    > Jeff Epler wrote:
    > > This seems to work, but it's undocumented (specifically,
    > > func_closure as
    > > an argument to new.function is undocumented) and makes my tummy feel
    > > funny when I think about it.
    > >
    > > >>> import new
    > > >>> def cell_get(cell):

    > > ... def f(): return cell
    > > ... return new.function(f.func_code, {}, "f", (), (cell,))()
    > > ...

    >
    > Rock. On.
    >
    > That is frickin' brilliant in at least three ways I never would have
    > thought of. :) Thanks! Looking back over Raymond's bytecode hack in PEP
    > 329, I notice he also used func_closure as an arg to function(). In
    > addition, he avoided importing the "new" module by just calling
    > type(f)().


    That wouldn't work in Python 2.2, I don't know what Jeff is using
    these days...

    Cheers,
    mwh

    --
    On the other hand, the following areas are subject to boycott
    in reaction to the rampant impurity of design or execution, as
    determined after a period of study, in no particular order:
    ... http://www.naggum.no/profile.html
     
    Michael Hudson, Apr 22, 2004
    #2
    1. Advertising

  3. Robert Brewer

    Jeff Epler Guest

    On Thu, Apr 22, 2004 at 10:34:13AM +0000, Michael Hudson wrote:
    > That wouldn't work in Python 2.2, I don't know what Jeff is using
    > these days...


    2.4 CVS .. what, doesn't everybody?

    Jeff
     
    Jeff Epler, Apr 22, 2004
    #3
    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. Richard Dixson
    Replies:
    1
    Views:
    542
    Joe Fallon
    May 18, 2004
  2. Richard Dixson
    Replies:
    2
    Views:
    756
    Richard Dixson
    May 18, 2004
  3. Jeff
    Replies:
    3
    Views:
    4,815
    Roedy Green
    Oct 11, 2003
  4. Robert Brewer

    Cell objects and their values

    Robert Brewer, Apr 22, 2004, in forum: Python
    Replies:
    0
    Views:
    277
    Robert Brewer
    Apr 22, 2004
  5. Stefan Schwarzer

    Naming future objects and their methods

    Stefan Schwarzer, Apr 14, 2012, in forum: Python
    Replies:
    2
    Views:
    306
    Stefan Schwarzer
    Apr 16, 2012
Loading...

Share This Page