[Python-ideas] objects aware of being bound to a name
andrew at acooke.org
Mon Jun 6 18:11:23 CEST 2011
I'm not sure what you're trying to do (ie if there's any practical problem
that motivates this), but in Lepl (a parser) I use a little trick that lets me
examine variables defined within a "with" scope. That lets me add "debugging"
at the application level.
There's an example here:
http://www.acooke.org/lepl/debugging.html#variable-traces - everything defined
inside the "with TraceVariables" is found by inspection of some Python
internals doo-hicky, and then modified to produce the debug output (note that
the output incldues the variable *names* which is the kind of thing you are
trying to do here).
Contact me if you want more info.
On Mon, Jun 06, 2011 at 09:48:07AM -0600, Eric Snow wrote:
> On Sat, Jun 4, 2011 at 11:50 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> > On Sun, Jun 5, 2011 at 11:54 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> >> Functions, classes, and modules have __name__ attributes (that cannot be
> >> deleted, even if they can be replaced). This attribute is set before they
> >> are optionally bound, so they also do not hear about the subsequent
> >> bindings. This attribute is used for their string representations for humans
> >> to read. I cannot think of any other use by the interpreter itself.
> > __name__ attributes are also relevant for serialisation (esp. pickling).
> > However, due to immutable objects, there's no realistic general
> > purpose solution in this space.
> Yeah, I think I was hasty on writing this up. It's interesting, but
> not a great fit, nor very practical. The immutable objects problem is
> definitely a show-stopper. Thanks for the feedback though.
> > Cheers,
> > Nick.
> > --
> > Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
> > _______________________________________________
> > Python-ideas mailing list
> > Python-ideas at python.org
> > http://mail.python.org/mailman/listinfo/python-ideas
> Python-ideas mailing list
> Python-ideas at python.org
More information about the Python-ideas