[pypy-dev] Fwd: Access the name of variable that is being assigned

William ML Leslie william.leslie.ttg at gmail.com
Wed Jul 16 00:17:55 CEST 2014


Ack, resend because pypy-dev does not set reply-to ...

On 16 July 2014 03:55, anatoly techtonik <techtonik at gmail.com> wrote:
> On Tue, Jul 15, 2014 at 12:50 PM, Yichao Yu <yyc1992 at gmail.com> wrote:
>> On Tue, Jul 15, 2014 at 5:05 PM, anatoly techtonik <techtonik at gmail.com> wrote:
>> I guess it would be better if you can describe what you really want to do.
>
> I described. Or you need use case or user story? I think I want to link
> object instances to variable names without to print those names
> (if possible) in __repr__ and debug messages to save time on
> troubleshooting.

The most common practice is to pass some kind of debugging info to the
constructor, otherwise, setting debug info on the instance is ok, too.

my_object = SomeClass()
my_object.debug_info = 'This is the typical case'

You can also use the inspect module to grab the source line of the caller:

http://codepad.org/YvStcEMv

-- 
William Leslie

Notice:
Likely much of this email is, by the nature of copyright, covered
under copyright law.  You absolutely MAY reproduce any part of it in
accordance with the copyright law of the nation you are reading this
in.  Any attempt to DENY YOU THOSE RIGHTS would be illegal without
prior contractual agreement.


More information about the pypy-dev mailing list