Printable string for 'self'

Steve Holden steve at holdenweb.com
Wed Mar 15 13:07:36 EST 2006


Don Taylor wrote:
> Fredrik Lundh wrote:
> 
>>objects don't have names in Python, and the source is not part of
>>the running program.
>>
>>have you read this ?
>>
>>    http://effbot.org/zone/python-objects.htm
> 
> 
> I have now.  Thank you very much.
> 
> "objects don't have names in Python": It appears from the code that 
> Michael posted that objects can discover the names that are bound to 
> themselves.  Is this true in general?  If so, then I guess it does not 
> matter which name I use as long as it is bound to the object.
> 
> "the source is not part of the running program" : Ok, but in my case I 
> would have the source that corresponds to the running program available 
> to me and the inspect module does appear to provide enough information 
> for me to find the corresponding piece of the source code.  Is there 
> something wrong with using the inspect module for this sort of work?
> 
> My overall intent is to try to build something that can record 
> interactions against an object so that they can be replayed later for 
> testing and debugging.  I had in mind to generate the recording as a 
> sequence of Python statements.  I would like to do this without 
> modifying the source of the target class.  At the moment this is just a 
> project to help me learn Python, although it would nice if it did yield 
> something useful.
> 
> Is there anything around that already does this sort of thing?
> 
Nothing springs to mind. However, given your statement of the overall 
intent, I should say that there's simply no need to record the "names" 
of the objects that are being modified.

Objects can indeed discover the names to which they are bound, albeit by 
a rather tortuous process of namespace introspection, but I don't see 
what advantages this offers in terms of how a given program modifies its 
environment (or namespace). Surely the important thing is that objects 
are created, modified in various ways, and finally destroyed?

If you are hoping to record "interactions against an object" without 
modifying the object's implementation I suspect your efforts may be 
doomed to failure. This opinion is offered mostly to motivate the many 
wrong-headed and knowledgeable individuals who would gain pleasure from 
proving my assertion incorrect and thereby helping you to solve your 
problem. Good luck.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd                 www.holdenweb.com
Love me, love my blog         holdenweb.blogspot.com




More information about the Python-list mailing list