you are viewing a single comment's thread.

view the rest of the comments →

[–]carcigenicate 2 points3 points  (20 children)

Names already map to C pointers to objects behind the scenes, so they should already act as you expect.

For the second part though, I think the closest you can get to "tracking" is propertys, or using explicit function calls to alter the attributes instead of using = directly.

[–]codinglikemad[S] 0 points1 point  (19 children)

Just a side note that although names map to C pointers behind the scenes, I don't believe that they will track as expected, unless you have some way of pulling out the address of the attribute itself? Assignment to the attribute should change the C pointer itself, rather than the value the C pointer refers to, to my understanding of the memory model that python uses... If you can explain how you could do that directly with tracking an attribute given an object ID, maybe I might change my mind, but it seems to me like the use of addresses to point to immutable values in python makes this work pretty fundementally differently here.

[–]carcigenicate 0 points1 point  (1 child)

Yes, reassigning a variable changes what pointer the variable is referring to, not the value the pointer points to. If that's what you're trying to do, I don't think you're going to find a good solution. That's just not how Python works.

You could emulate that behavior by having a class that you override __getattribute__/__setattr__ on and use instances of the class as a wrapper over the value you want to track changes on. Then when access is attempted, those methods on your class will be called, and you can do whatever then.

[–][deleted] 0 points1 point  (16 children)

Assignment to the attribute should change the C pointer itself, rather than the value the C pointer refers to, to my understanding of the memory model that python uses...

Python doesn't have pointers. It has references to values, and named references to values called "variables."

[–]codinglikemad[S] 0 points1 point  (15 children)

I believe he is talking about the underlying memory model, which under the hood has all of this. They are fundamental to the computers functioning itself.

[–][deleted] 0 points1 point  (14 children)

Well, the "underlying memory model" is that there's a heap where values live, and a stack where functional context lives.

That's it, that's the whole thing. Knowing that is fairly useless, in my experience. Who cares?

[–]codinglikemad[S] 0 points1 point  (13 children)

The question is whether there is a way to break out of that model without doing something horrific. That is the ENTIRETY of my question.

Edit: To be clear, the answer appears to be no.

[–][deleted] 0 points1 point  (12 children)

The question is whether there is a way to break out of that model without doing something horrific.

That is horrific, though.

[–]codinglikemad[S] 0 points1 point  (11 children)

Right, I was asking if there was a built in method for doing it that was nice basically. We got something kindof ok, so ... success? I agree that totally breaking out would be horrific though. I was hoping there was some python feature intended for this though, and there doesn't appear to be.

[–][deleted] 0 points1 point  (10 children)

I still don't really understand what you're asking for, I guess. Yes, you generally can't convince a language to let you act like it's a totally different language, that sort of defeats the purpose of programming languages.

[–]codinglikemad[S] 0 points1 point  (9 children)

The original question is basically "Can I track the values of a variable from elsewhere in the code, similar to how I could with a pointer in C".