Re: Accessing the contents of a 'cell' object from Python

Discussion in 'Python' started by paul cannon, Mar 16, 2005.

  1. paul cannon

    paul cannon Guest

    On Tue, Mar 15, 2005 at 03:08:19PM -0700, paul cannon wrote:
    > Having poked around a little bit, I found there doesn't appear to be any
    > way to get at the contents of a cell object from Python. It's not the
    > sort of thing that one needs to be doing very frequently, but I've run
    > into a few situations recently where it would be really useful from a
    > debugging standpoint.


    Okay, I did come up with one solution- create a new function that just
    returns a value from its own closure, and manufacture its closure from
    the cell you already have.

    So..

    import new
    def get_cell_value(cell):
    return new.function(
    (lambda x: lambda: x)(0).func_code, {}, None, None, (cell,)
    )()

    It could be optimized a bit by precalculating the code object.

    I do still think the earlier solution (giving the cell objects a method)
    is cleaner and better long-term, but this will do.

    --
    paul
     
    paul cannon, Mar 16, 2005
    #1
    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. Don Adams
    Replies:
    1
    Views:
    624
    Martin Honnen
    Mar 5, 2004
  2. paul cannon
    Replies:
    0
    Views:
    300
    paul cannon
    Mar 15, 2005
  3. Jeff Epler
    Replies:
    1
    Views:
    352
    Duncan Booth
    Mar 16, 2005
  4. John Doe

    accessing object contents

    John Doe, Mar 19, 2011, in forum: Ruby
    Replies:
    2
    Views:
    102
    Brian Candler
    Mar 19, 2011
  5. Justin C
    Replies:
    4
    Views:
    175
    Justin C
    Jul 10, 2006
Loading...

Share This Page