Learn the object inheritance of Python

Source: Internet
Author: User

Python is an object-oriented language and the following is my extension to the Configparaser.configparaser object. Added the Get_client method to the decomposition process of the custom parameter.

#coding =utf-8import configparserimport re# objects inherit from Object Configparser.configparserclass Config (configparser.configparser) : "    extract from server list data    configuration information Instance    [hosts]    client = Root:[email Protected]^[email protected]:3306,root:[ Email protected]:3306    Multiple servers are separated by the English bean number    Example    import libs.configure as config    conf = config. Config ()    conf.read ("default.conf")    clinets = Conf.get_client ("Hosts", "Client") "    def get_ Client (Self, section, option):        Item   = self.get (section, option)        values = Item.split (",")        confs< c17/>= {} for        conf in values:            match = Re.match (r "(\w+?):(. +) @ ([^:]+):(\d+) ", conf)            if match:                user,password,host,port = match.groups ()                confs[host] = {" Host ": Host, "User": User, "password":p assword, "port": Int (port)}        return Confs


Learn the object inheritance of Python

Related Article

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.