Python __get__ & __set__

Source: Internet
Author: User

Objective:

Provides something similar to Getter/setter in Java.

(The purpose of getter/setter: To make attributes more simple by making them easier to reference---especially for future read/assignment of properties)

Official Concise document:

Https://docs.python.org/2/howto/descriptor.html

Good introduction to English (details of the ins and outs):

http://martyalchin.com/2007/nov/23/python-descriptors-part-1-of-2/

Profile:

1. Method of implementing attributes/variables

2. Python's handling is slightly strange (implemented by an external Descripter class), but it's not surprising.

3. Since the reference class is not allowed to be modified at run time, only the __get__ function has a reference class (Reffer_obj_type) parameter passed in

  

def __get__ (self, Refer_obj, Refer_obj_type):    Pass

4. An instance of the Descripter class, (Beginner's mind) is best referred to by its class invocation, rather than by the instance of the referenced person.

However, there is nothing wrong with invoking it on the instance of the referrer (the Refer_obj parameter is not none at this time)

Python __get__ & __set__

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.