第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

python配置文件練習操作

標簽:
Python Linux
源码
#!/usr/bin/env python
# coding=utf-8
#import os
import ConfigParser 
'''
1: dump ini
2: del section
3: del item
4: modify item
5: add section
6: save modify
'''

class student_info(object):

    def __init__(self, recordfile):
        self.logfile = recordfile
        self.cfg = ConfigParser.ConfigParser()

    def cfg_load(self):
        self.cfg.read(self.logfile)

    def cfg_dump(self):
        se_list = self.cfg.sections()
        print("====================>")
        for se in se_list:
            print se
            print self.cfg.items(se)
        print("<====================")

    def delete_item(self, section, key):
        self.cfg.remove_option(section, key)

    def delete_section(self, section):
        self.cfg.remove_section(section)

    def add_setction(self, section):
        self.cfg.add_section(section)

    def set_item(self, section, key, value):
        self.cfg.set(section, key, value)

    def save(self):
        fp = open(self.logfile, 'w')
        self.cfg.write(fp)
        fp.close()

if __name__ == '__main__':
    info = student_info('./imooc.txt')
    info.cfg_load()
    info.cfg_dump()
    info.set_item('userinfo', 'pwd', 'abc')
    info.cfg_dump()
    info.add_setction('login')
    info.set_item('login', '2016-1008', '20')
    info.cfg_dump()
    info.save()
imooc.txt
[userinfo]
name = johntian
pwd = abc

[study]
python_base = 15
python_junior = 20
linux_base_ = 15

来自:Python文件处理--文件练习

點擊查看更多內容
1人點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質文章

正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消