Alternative access methods for private properties

Source: Internet
Author: User

#-*-coding:utf-8-*-#python#Xiaodeng#http://blog.itpub.net/26250550/viewspace-1411768/#alternative access Methods for private properties#这里利用的好像是一种伪私有的机制classMyClass ():def __init__(self): self.__name='Xiaodeng'Self.age=28defPrintname (self):returnSelf.__name        def __printage(self):returnSelf.ageif __name__=='__main__':    Printa=MyClass ()#gets all properties of the class, _myclass__name as private property    PrintA.__dict__#{' age ': +, ' _myclass__name ': ' Xiaodeng '}    #all properties of the instantiated object are viewed through a.__dict__, where the private property name is displayed as _myclass__name; _myclass__name    #You can access the properties of name as a whole    #as follows:    Print     PrintA._myclass__name

Alternative access methods for private properties

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.