Python Module Class 2 preliminary

Source: Internet
Author: User

Module One, Configparser
== V3

1. Get all nodes

Import= configparser. Configparser () config.read ('settings', encoding='utf-8' = Config.sections ()print (res) 

2. Gets all the key-value pairs under the specified node

Import= configparser. Configparser () config.read ('settings', encoding='utf-8' = Config.items ('section1')print (res) 

3, get all the keys under the node

Import= configparser. Configparser () config.read ('settings', encoding='utf-8' = Config.options ('section1')print (res) 

4. Gets the value of the specified key under the specified node

Importconfigparser config=Configparser. Configparser () Config.read ('Settings', encoding='Utf-8') v= Config.get ('Section1','K1')#v = config.getint (' Section1 ', ' K1 ')#v = config.getfloat (' Section1 ', ' K1 ')#v = config.getboolean (' Section1 ', ' K1 ') Print(v)

5. Check, delete, add nodes

Importconfigparser config=Configparser. Configparser () Config.read ('Settings', encoding='Utf-8')  #CheckHas_sec = Config.has_section ('Section1')Print(has_sec)#Adding nodesConfig.add_section ("sec_1") config.write (open ('Settings','W')) #Delete a nodeConfig.remove_section ("sec_1") config.write (open ('Settings','W'))

6. Check, delete, set the key value pairs within the specified group

Importconfigparser config=Configparser. Configparser () Config.read ('Settings', encoding='Utf-8') #Checkhas_opt = Config.has_option ('Section1','K1')Print(has_opt)#DeleteConfig.remove_option ('Section1','K1') config.write (open ('Settings','W')) #SetConfig.set ('Section1','K10',"123") config.write (open ('Settings','W'))

Python Module Class 2 preliminary

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.