"Python" Class (Data + doubts)

Source: Internet
Author: User

1.http://python-china.org/t/77 understanding of Method binding

2.[python] Dir () differs from __dict__,__slots__

3.Descriptor HowTo Guide

4. How do I understand Python's descriptor?

5. Concise Python Magic-1

6. Concise Python Magic-2

7. Explain the differences between __get__ and __getattr__ and __getattribute__ in Python

8. Custom Classes

What is the relationship between type 9.Python and object?

Why do the next few pieces of code work correctly and what happens at runtime???

classMyInt (int):def __init__(Self, v):Pass    defSquare (self):returnSelf * SelfdefHello ():Print 'Hello'N= MyInt (2)PrintN.__dict__PrintMyInt.__dict__N.hello=Hellon.hello ()PrintN.__dict__
ImportTypesclassLog (object):def __init__(self, f): Self.f=Fdef __get__(SELF,OBJ,CLS):PrintSelf.f.__name__,'called'        returntypes. Methodtype (SELF.F, obj, CLS)classC (object): @Logdeff (self):PassC=C () c.f ()
classC1 (object): a='ABC'    def __getattribute__(Self, *args, * *Kwargs):Print("__getattribute__ () is called")        returnObject.__getattribute__(Self, *args, * *Kwargs)def __getattr__(self, name):Print("__getattr__ is called")        returnName +"From getattr"    def __get__(self, instance, owner):Print("__get__ () is called", instance, owner)return Selfdeffoo (self, x):Print(x)classC2 (object): D=C1 ()if __name__=="__main__": C=C1 () C2=C2 ()Print "====="    Print(C.A)Print "------"    Print(c.zzzz)Print "------"c2.dPrint "------"    Print(C2.D.A)

"Python" Class (Data + doubts)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.