[root@linag python]# vim config.py

import configparser

config = configparser.ConfigParser()
config["DEFAULT"] = {'ServerAliveInterval': '',
'Compression': 'yes',
'CompressionLevel': ''}
config['bitbucket.org'] = {}
config['bitbucket.org']['User'] = 'Root' config['topsecret.server.com'] = {}
topsecret = config['topsecret.server.com']
topsecret['Host Port'] = ''
topsecret['Forward'] = 'yes' config['DEFAULT']['Forward'] = 'No' with open('example.ini','w') as configfile:
config.write(configfile) config.set('topsecret.server.com','Hosr Port','') #改 config.remove_section('topsecret.server.com') #删
config.write(open ('xml.ini','w')) [root@linag python]# python config.py [root@linag python]# cat example.ini
[DEFAULT]
serveraliveinterval = 45
compression = yes
compressionlevel = 9
forward = No [bitbucket.org]
user = Root [topsecret.server.com]
host port = 5200
forward = yes [root@linag python]# cat xml.ini
[DEFAULT]
serveraliveinterval = 45
compression = yes
compressionlevel = 9
forward = No [bitbucket.org]
user = Root

python 之 configparser 模块的更多相关文章

  1. python封装configparser模块获取conf.ini值(优化版)

    昨天晚上封装了configparser模块,是根据keyname获取的value.python封装configparser模块获取conf.ini值 我原本是想通过config.ini文件中的sect ...

  2. python中confIgparser模块学习

    python中configparser模块学习 ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(section ...

  3. Python中ConfigParser模块应用

    Python中ConfigParser模块应用 Python的ConfigParser模块定义了3个对INI文件进行操作的类 RawConfigParser.ConfigParser和SafeConf ...

  4. python中configparser模块读取ini文件

    python中configparser模块读取ini文件 ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(se ...

  5. python 的ConfigParser模块

    Python 之ConfigParser模块 一.ConfigParser简介 ConfigParser 是用来读取配置文件的包.配置文件的格式如下:中括号“[ ]”内包含的为section.sect ...

  6. Python自动化测试 -ConfigParser模块读写配置文件

    C#之所以容易让人感兴趣,是因为安装完Visual Studio, 就可以很简单的直接写程序了,不需要做如何配置. 对新手来说,这是非常好的“初体验”, 会激发初学者的自信和兴趣. 而有些语言的开发环 ...

  7. python封装configparser模块获取conf.ini值

    configparser模块是python自带的从文件中获取固定格式参数的模块,因为是python只带的,大家用的应该很多,我觉得这个参数模块比较灵活,添加参数.修改参数.读取参数等都有对应的参数供用 ...

  8. python中configparser模块的使用

    configparser模块用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser. 首先要写一个如下所示的配置文件: [DEFAULT] serv ...

  9. (转)python的ConfigParser模块

    原文:https://blog.csdn.net/miner_k/article/details/77857292 如何使用Python3读写INI配置文件-------https://blog.cs ...

  10. python 配置文件 ConfigParser模块

    ConfigParser模块 用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser. 来看一个好多软件的常见文档格式如下 [DEFAULT] Se ...

随机推荐

  1. ImageMagick - 设置透明带 AlphaChannel 的 png 图片的透明度

    学习和使用ImageMagick也有几年时间了,其实对 ImageMagick 的了解还仅仅是皮毛吧. 最近在写代码的时候,遇到一个调整透明png图片透明度的问题: 当1张png图片,有些区域是透明的 ...

  2. Python模块之time、random、os、sys、序列化、re

    Time模块 和时间有关系的我们就要用到时间模块.在使用模块之前,应该首先导入这个模块. #常用方法 1.time.sleep(secs) (线程)推迟指定的时间运行.单位为秒. 2.time.tim ...

  3. [转]深入理解CSS中的层叠上下文和层叠顺序

    http://www.zhangxinxu.com/wordpress/2016/01/understand-css-stacking-context-order-z-index/ 零.世间的道理都是 ...

  4. (BFS 二叉树) leetcode 515. Find Largest Value in Each Tree Row

    You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3 2 / \ \ 5 3 ...

  5. MYSQL二进制5.7.安装

    一.下载MySQL二进制软件包 下载连接:MYSQ安装包下载 官网MySQL有四个版本:GA版.DMR版.RC版.Beta版.一般生产和测试环境使用GA版(常规可用的版本,经过bug修复测试) 二.安 ...

  6. Struts2中文件上传下载实例

    1.单文件上传 jsp页面: <!-- 单文件上传 --> <form action="Fileupload.action" method="post& ...

  7. CodeForces5E 环转链,dp思想

    http://codeforces.com/problemset/problem/5/E 众所周知,在很久以前,在今天的 Berland 地区,居住着 Bindian 部落.他们的首都被 n 座山所环 ...

  8. flask 钩子函数

    说明: before_request函数,就是一个装饰器,他可以把需要设置为钩子函数的代码放到视图函数执行之前执行 示例: from flask import Flask,url_for,redire ...

  9. 利用 JMetal 实现大规模聚类问题的研究(二) JMetal代码总览

    之前完成了导入JMetal到自己的工程这一步. 在开始我们研究的问题之前,我们先对JMetal的源代码一个全局的认识. JMetal很好地利用了面向对象的特性,对所有的优化问题做了高度的抽象,建议有空 ...

  10. zookeeper安装(单机版)

    1:查看当前服务器IP: # ifconfig 情况1:直接可以看到自己的IP:192.168.164.130 情况2:看不到自己的IP(但是能看到ifcfg-开头的东西,如:ifcfg-eno167 ...