473,545 Members | 721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cell object dereferencing

Is there a way to dereference a cell object (that is, get
the object that it references to) in Python?

Regards, Jan

--
Jan Decaluwe - Resources bvba - http://jandecaluwe.com
Losbergenlaan 16, B-3010 Leuven, Belgium
Bored with EDA the way it is? Check this:
http://jandecaluwe.com/Tools/MyHDL/Overview.html

Jul 18 '05 #1
8 3039
Jan Decaluwe wrote:
Is there a way to dereference a cell object (that is, get
the object that it references to) in Python?

Regards, Jan


I appreciate messages from the future, cryptic as they may be.
So: what cell in what prison?

Sorry, couldn't resist...

Peter
Jul 18 '05 #2
Peter Otten wrote:
Jan Decaluwe wrote:

Is there a way to dereference a cell object (that is, get
the object that it references to) in Python?

Regards, Jan

I appreciate messages from the future, cryptic as they may be.
So: what cell in what prison?

Sorry, couldn't resist...


Cell objects are afaik only documented briefly in the Python C API,
so I understand the question may sound cryptic.
For you knowledge, they exist today and are used to implement
nested scopes. The guy able to answer (I hope)
will probably understand the question immediately.

Regards, Jan

--
Jan Decaluwe - Resources bvba - http://jandecaluwe.com
Losbergenlaan 16, B-3010 Leuven, Belgium
Bored with EDA the way it is? Check this:
http://jandecaluwe.com/Tools/MyHDL/Overview.html

Jul 18 '05 #3

"Jan Decaluwe" <ja*@jandecaluw e.com> wrote in message
news:3F******** ******@jandecal uwe.com...
Is there a way to dereference a cell object (that is, get
the object that it references to) in Python?


[Background: a cell is an undefined internal implementation object used to
make nested scoping work as advertised. One might think of it as a means
for persisting cross-scope name-binding of objects in intermediate nested
scopes of nested functions. Alternatively, a cell is 'persistent read-only
shadow of an outer local'. For nested functions that access intermediate
locals, .func_closure is a tuple of 'cells'.]

Yes and no, depending on what you mean be 'dereference'. Within the nested
function, you 'dereference' the variable the same way you do any bound
ame -- write it! Outside the function, where the variable has no
conceptual existence, you can grab a cell from the func_closure tuple, but I
know of no way to access its value. Both repr() and str() return a <cell at
xxx: type at yyy> description. If you want a globally accessible value, use
a global variable.

Terry J. Reedy
Jul 18 '05 #4
Terry Reedy wrote:
"Jan Decaluwe" <ja*@jandecaluw e.com> wrote in message
news:3F******** ******@jandecal uwe.com...
Is there a way to dereference a cell object (that is, get
the object that it references to) in Python?

[Background: a cell is an undefined internal implementation object used to
make nested scoping work as advertised. One might think of it as a means
for persisting cross-scope name-binding of objects in intermediate nested
scopes of nested functions. Alternatively, a cell is 'persistent read-only
shadow of an outer local'. For nested functions that access intermediate
locals, .func_closure is a tuple of 'cells'.]

Yes and no, depending on what you mean be 'dereference'. Within the nested
function, you 'dereference' the variable the same way you do any bound
ame -- write it! Outside the function, where the variable has no
conceptual existence, you can grab a cell from the func_closure tuple, but I
know of no way to access its value.


This is what is mean - so I guess the answer is no.
Both repr() and str() return a <cell at
xxx: type at yyy> description. If you want a globally accessible value, use
a global variable.


The background is that I am writing a small compiler that translates a
(small) subset of Python into another language. I would like to be able to
support free variables as they are likely to be useful in the kind of
code I'm targetting. However, I need to be able to inspect the corresponding
objects for their type etc. Conceptually this should be possible, just as
with globals and locals of functions and frames, but in practice it seems
it isn't - a real pity for which I hope to find a workaround.

Regards, Jan

--
Jan Decaluwe - Resources bvba - http://jandecaluwe.com
Losbergenlaan 16, B-3010 Leuven, Belgium
Bored with EDA the way it is? Check this:
http://jandecaluwe.com/Tools/MyHDL/Overview.html

Jul 18 '05 #5
Jan Decaluwe wrote:
Is there a way to dereference a cell object (that is, get
the object that it references to) in Python?


I got the following response from Samuele Pedroni. I'll repost this
first, and then start thinking about it :-)

--

[I was reading the news group through google, feel free to repost this]

well you can write a C extension or use this hack (it's a huge hack but it is safe
and does the trick):

def proto_acc(v=Non e):
def acc():
return v
return acc
acc0 = proto_acc()
import new
make_acc = lambda cell: (new.function (acc0.func_code ,acc0.func_glob als,'#cell_acc' ,acc0.func_defa ults,(cell,)))

def cell_deref(cell ):
return make_acc(cell)( )

# usage

def g(x,y):
def f(): return x,y
return f

f=g(1,2)

f_cells_by_name = dict(zip(f.func _code.co_freeva rs,f.func_closu re))

print cell_deref(f_ce lls_by_name['x'])
print cell_deref(f_ce lls_by_name['y'])

regards.
--
Jan Decaluwe - Resources bvba - http://jandecaluwe.com
Losbergenlaan 16, B-3010 Leuven, Belgium
Bored with EDA the way it is? Check this:
http://jandecaluwe.com/Tools/MyHDL/Overview.html

Jul 18 '05 #6

"Jan Decaluwe" <ja*@jandecaluw e.com> wrote in message
news:3F******** ******@jandecal uwe.com...
Jan Decaluwe wrote:
Is there a way to dereference a cell object (that is, get
the object that it references to) in Python?
I got the following response from Samuele Pedroni.:

well you can ... use this hack (it's a huge hack but it is safe and does the trick):
def proto_acc(v=Non e):
def acc():
return v
return acc
acc0 = proto_acc() import new
make_acc = lambda cell: (new.function (acc0.func_code ,acc0.func_glob als,'#cell_acc' ,acc0.func_defa ults,(cell,))) def cell_deref(cell ):
return make_acc(cell)( )


Cute, Samuele. If function.func_c losure were writable (which it is not)
then I believe the last four lines could be condensed as the more readable

def cell_deref(cell ):
acc0.func_closu re = (cell,)
return acc0()

but since it is not, you instead make a new function that is a near copy of
acc0 but with (cell,) substituted as *its* func_closure.

Terry J. Reedy
Jul 18 '05 #7
Terry Reedy wrote:
"Jan Decaluwe" <ja*@jandecaluw e.com> wrote in message
news:3F******** ******@jandecal uwe.com...
Jan Decaluwe wrote:
Is there a way to dereference a cell object (that is, get
the object that it references to) in Python?


I got the following response from Samuele Pedroni.:


well you can ... use this hack (it's a huge hack but it is safe and does


the trick):

def proto_acc(v=Non e):
def acc():
return v
return acc
acc0 = proto_acc()


import new
make_acc = lambda cell: (new.function


(acc0.func_code ,acc0.func_glob als,'#cell_acc' ,acc0.func_defa ults,(cell,)))
def cell_deref(cell ):
return make_acc(cell)( )

Cute, Samuele. If function.func_c losure were writable (which it is not)
then I believe the last four lines could be condensed as the more readable

def cell_deref(cell ):
acc0.func_closu re = (cell,)
return acc0()

but since it is not, you instead make a new function that is a near copy of
acc0 but with (cell,) substituted as *its* func_closure.


Aha, *that's* what the last argument is: func_closure. For those interested,
this is not yet in the documentation of module new, but it is documented
in new.function.__ doc__.

Thanks a lot for this hack, it looks just what I need. I even start to
understand it, I believe. (Next thing I would like to understand is
how the hell you came up with this!)

Regards, Jan

--
Jan Decaluwe - Resources bvba - http://jandecaluwe.com
Losbergenlaan 16, B-3010 Leuven, Belgium
Bored with EDA the way it is? Check this:
http://jandecaluwe.com/Tools/MyHDL/Overview.html

Jul 18 '05 #8

"Jan Decaluwe" <ja*@jandecaluw e.com> wrote in message
(Next thing I would like to understand is how the hell you came up with

this!)

I can't speak for Pedroni, but...
If you start with the two facts I initially stated -- cells are externally
accessible as .func_closure tuple members but their values are only
internally accessible -- and treat them as design guidelines (as Pedroni
did) rather than as deniers of possibility (my mistake), one is pretty much
lead to the conclusion that you need to attach the cells to a function that
reads and returns the value. This is Pedroni's template function. The
third fact -- that .func_closure is read-only, dictates the near-copy via
new instead of simple reuse of the template.

Terry

Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3398
by: John Ratliff | last post by:
When I dereference a pointer, does it make a copy of the object? Say I had a singleton, and wanted an static method to retrieve it from the class. class foo { private: static foo *bar; foo() {} // no public creation!
1
3533
by: Thanks | last post by:
I have a routine that is called on Page_Init. It retrieves folder records from a database which I display as Link Buttons in a table cell. I set the table cell's bgcolor to a default color (say black for example). I am dynamically creating the LinkButton controls and adding them into the table cell and I've also hooked up an event handler for...
2
3630
by: Chuck Hartman | last post by:
I've been trying to add an ImageButton object to a Calendar table cell, but so far I am unable to handle the Command event from that button in my form's code behind. Below is an example of what I am trying to do. The ImageButton that is on the form handles its Command event just fine, but the ImageButton that is added to the cell does not...
2
3171
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchTopQuestionsAboutASPNETDataGridServerControl.asp, Selecting Rows by Clicking Anywhere). Private Sub DataGrid1_ItemDataBound(ByVal...
18
8269
by: Frank M. Walter | last post by:
Hello, I have made an small AddIn with udf for excel 2003. I use vs2003. The point of view is the function __T() I call it in excel sheet writing =__T() I am not able to set a value to a given cell. region.Value2="qwe"; //bumm! A exception will be trown. On all PCs with excel. HRESULT 0x800A03EC
3
14558
by: Rich | last post by:
Hello, If I want to update data displayed in a datagrideview/datagridview cell, how can I determine what cell I am updating? I am looking at the click event below, for example. Can I get information from the sender object or the EventArgs? How? Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
13
3144
by: Mike S | last post by:
I came across the following paragraph in the "Semantics" section for simple assignment in N1124 (C99 draft) and I'm wondering if I'm interpreting it right: 6.5.16.1p3: If the value being stored in an object is read from another object that overlaps in any way the storage of the first object, then the overlap shall be exact and the two...
6
2017
TMS
by: TMS | last post by:
This spreadsheet is almost done, but there is some functionality that is driving me nuts. For instance: a cell, for instance 'a0' is to have 'a0' as a string, but if something is entered like '4+5', that is also there. So, at any time, one could see the cell number a0 or they could click on it and have the equation show as well. Right...
4
2844
by: John Nagle | last post by:
I'm printing out each entry in "gc.garbage" after a garbage collection in DEBUG_LEAK mode, and I'm seeing many entries like <cell at 0x00F7C170: function object at 0x00FDD6B0> That's the output of "repr". Are "cell" objects created only from external C libraries, or can regular Python code generate them? Is there any way to find out...
0
7465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7416
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5325
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.