Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Accessing the contents of a 'cell' object from Python

Thread Tools

Accessing the contents of a 'cell' object from Python

paul cannon
Posts: n/a
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.

You can get at a cell object containing a given value by making a quick
closure and looking at the func_closure attribute:

(lambda x: lambda: x)(some_value).func_closure[0]

but there's not anything we can easily do with that object to find out
what it's pointing at. The str() representation helpfully tells us the
id of the contained value, but I'm not aware of a way to get at an
object given its id [1].

So I thought it might be useful to add such a method to the cell object
type. Attached is a sample patch that does so (against python2.4). Does
this look like the sort of thing that would be useful to anyone else?

How does one go about getting small changes like this into Python


[1] Yes, the id is the object's pointer in cPython, but even I don't
think it would be a good idea to allow accessing an object via the id,
even if it's possible.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
accessing object contents John Doe Ruby 2 03-19-2011 09:20 PM
Adding contents on yaml file without overwriting actual contents Kamarulnizam Rahim Ruby 4 01-28-2011 09:10 AM
Re: Accessing the contents of a 'cell' object from Python Jeff Epler Python 1 03-16-2005 10:01 AM
Re: Accessing the contents of a 'cell' object from Python paul cannon Python 0 03-16-2005 12:12 AM
Can I restrict both attribute contents and element contents in schema Don Adams XML 1 03-05-2004 12:48 PM