python3 configparser对配置文件读写
import configparser #read data from conf file
cf=configparser.ConfigParser()
cf.read("biosver.cfg") #返回所有的section
s=cf.sections()
print(s) #返回information section下面的option
o1=cf.options('Information')
print(o1) #返回information section下面的option的具体的内容
v1=cf.items("Information")
print(v1) #得到指定项的值
name=cf.get('Information','name')
print(name) #添加section if cf.has_section("del"):
print("del section exists")
else:
cf.add_section('del')
cf.set("del","age","12")
cf.write(open("biosver.cfg","w"))
#删除option
if cf.has_option("del",'age'):
print("del->age exists")
cf.remove_option("del","age")
cf.write(open("biosver.cfg","w"))
print("delete del->age")
else:
print("del -> age don't exist")
#删除section
if cf.has_section("del1"):
cf.remove_section("del1")
cf.write(open("biosver.cfg","w"))
else:
print("del1 don't exists")
#modify a value
cf.set("section","option","value")
python3 configparser对配置文件读写的更多相关文章
- python3使用ConfigParser从配置文件中获取列表
使用python3使用ConfigParser从配置文件中获取列表 testConfig.py #!/usr/bin/env python # coding=utf- __author__ = 'St ...
- python3使用configparser读取配置文件
python2中的ConfigParser在python3中改成了configparser 1.配置文件格式是 [域名] k=v 2.代码示例:需要生成conf.ini配置文件如下:[config]v ...
- 转 python3 读取 ini配置文件
在代码中经常会通过ini文件来配置一些常修改的配置.下面通过一个实例来看下如何写入.读取ini配置文件. 需要的配置文件是: 1 [path] 2 back_dir = /Users/abc/Pych ...
- .NET平台开源项目速览(1)SharpConfig配置文件读写组件
在.NET平台日常开发中,读取配置文件是一个很常见的需求.以前都是使用System.Configuration.ConfigurationSettings来操作,这个说实话,搞起来比较费劲.不知道大家 ...
- 纯C#的ini格式配置文件读写
虽然C#里都是添加app.config 并且访问也很方便 ,有时候还是不习惯用他.那么我们来做个仿C++下的那种ini配置文件读写吧,其他人写的都是调用非托管kernel32.dll.我也用过 但是感 ...
- LIB 配置文件读写器
由于读写配置文件的次数比较频繁,而且拥有众多的类库,到最后,直接被各种各样的类库烦死. 顺手封一个简单,实用的.主要功能: 读写AppSetting 读取连接字符串 读取自定义配置节 using Sy ...
- python ConfigParser读取配置文件,及解决报错(去掉BOM)ConfigParser.MissingSectionHeaderError: File contains no section headers的方法
先说一下在读取配置文件时报错的问题--ConfigParser.MissingSectionHeaderError: File contains no section headers 问题描述: 在练 ...
- c# Config配置文件读写
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...
- 记一次用python 的ConfigParser读取配置文件编码报错
记一次用python 的ConfigParser读取配置文件编码报错 ...... raise MissingSectionHeaderError(fpname, lineno, line)Confi ...
随机推荐
- javascript 实现 接口编程
// Constructor. var Interface = function (name, methods) { if (arguments.length != 2) { throw new Er ...
- JS add script tag to dynamically call script
//IE: var script = document.createElement("script"); script.setAttribute("type", ...
- linux 下 多进程与多线程
[Linux]多进程与多线程之间的区别 http://blog.csdn.net/byrsongqq/article/details/6339240 网络编程中设计并发服务器,使用多进程与多线程 ,请 ...
- c# redis 利用锁(StackExchange.Redis LockTake)来保证数据在高并发情况下的正确性
之前有写过一篇介绍c#操作redis的文章 http://www.cnblogs.com/axel10/p/8459434.html ,这篇文章中的案例使用了StringIncrement来实现了高并 ...
- HDU 1568 Fibonacci【求斐波那契数的前4位/递推式】
Fibonacci Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Proble ...
- Network | Cookie and Session
Cookies are arbitrary pieces of data chosen by the web server and sent to the browser. The browser r ...
- Decrease (Judge ver.)
题目描述 We have a sequence of length N consisting of non-negative integers. Consider performing the fol ...
- Linux安全漏洞审计工具Lynis
Linux安全漏洞审计工具Lynis Lynis是针对类Unix系统的审计工具,它支持Unix.Linux.FreeBSD.Mac OS多种操作系统.它能对系统实施大于400种测试,以发现39个方 ...
- Hadoop1和Hadoop2的区别是什么?
[学习笔记] Hadoop1和Hadoop2的区别是什么?马 克-to-win @ 马克java社区:原来的Hadoop1的Mapreduce又管资源管理,又管数据处理和计算.而Hadoop2中的Ma ...
- 基于WPF系统框架设计(3)-Fluent Ribbon界面布局
一个系统框架除了功能菜单导航,有系统内容显示区域,系统状态栏. Silver: Blue: Black: 系统界面设计,就不进行技术细节介绍了,主题以框架设计为主,Xaml源码参考: <Flue ...