Can you use self in __str__

Shiyao Ma i at introo.me
Sat Nov 29 04:16:55 CET 2014


2014-11-28 13:00 GMT+08:00 Chris Angelico <rosuav at gmail.com>:
> On Fri, Nov 28, 2014 at 2:04 PM, Shiyao Ma <i at introo.me> wrote:
>> What if it's in the local namespace of a function or method? IDK, try
>> to get that thing first.
>
Sure enough. I will even avoid using "id" as it's dependent on CPython
implementation. :)

> What if it's in multiple namespaces? What if it's not in any at all?
> Your solution is not going to work in the general case, AND it's a bad
> idea.
> Please don't do this in any code that I'll ever have to
> maintain.
No way. You will never get my project code in such a form. I am way
more peculiar about readability and robustness than most of my other
ppl.
The point is, the bpate is just for demonstration to show there is a
*possible* way to find the name even you didn't specify it at first
hand.




-- 

吾輩は猫である。ホームーページはhttp://introo.me。



More information about the Python-list mailing list