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 ...
随机推荐
- 《Java性能权威指南》笔记----Java性能调优工具
OS 1.CPU 用户态时间(us):cpu执行应用代码所占时间的百分比. 内核态时间(sy):cpu执行内核代码所占时间的百分比,系统态时间与应用相关. 空闲时间(id):cpu空闲时间百分比.空闲 ...
- FusionCharts参数说明补充
原文发布时间为:2010-09-14 -- 来源于本人的百度文章 [由搬家工具导入] 功能特性animation 是否动画显示数据,默认为1(True)showN ...
- Java中的IO基本用法
先贴一下我在作业中用到的三种文件输入辅助类.三种文件输出辅助类 public class BuffIn implements InHelp{ private BufferedReader buffer ...
- [LeetCode] Reverse Bits 位操作
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- nslookup命令详解【转】
转自:http://blog.chinaunix.net/uid-28933499-id-3750357.html NSlookup命令的用法 用了域名服务器后,经常要查询域名的解析情况,nslook ...
- alloc_chrdev_region申请一个动态主设备号,并申请一系列次设备号
ret = alloc_chrdev_region(&ndev, 0, 1, "chr_dev"); //分配设备号 alloc_chrdev_region申请一个动态主设 ...
- (11)centos之vim使用
ZZ 保存并退出 :x 保存并退出 :q 不保存退出
- 在Linux 双机下自己手动实现浮动ip技术
两台Linux服务器,一台为主机(IP:124.158.26.30)对外提供了一定的网络服务,另一台从机(IP:124.158.26.31)能提供相同的服务,但ip地址没有对外部公开客户端连接的都是1 ...
- ACM的奇计淫巧_输入挂
什么是输入挂? 众所周知scanf比cin快的多,那么有没有比scanf更快的东西呢?答案就是输入挂,输入挂利用了告诉读取的函数getchar(),然后再人工处理成整数或浮点,比使用scanf快太多. ...
- BZOJ 3881 COCI 2015 Divljak
题面 Description Tom有n个字符串S1,S2...Sn,Jerry有一个字符串集合T,一开始集合是空的. 接下来会发生q个操作,操作有两种形式: "1 P",Jerr ...