day6_python之configparser_模块
configparser_模块是为了解析.ini文件的配置
a.ini
[xiechao] name=xiechao
age=18
is_admin=True salary=1000000.12 [xiemingyuan] name=xiechao
age=3
is_admin=True salary=False
1、查看a.ini
import configparser config = configparser.ConfigParser()
config.read('a.ini') print(config.sections()) #看标题,看整个文件中有多少个标题 print(config.options(config.sections()[0])) #查看第一个标题下边的配置项有哪些 print(config.get('xiechao','name'))#查看某个标题下的某个配置项的值 res = config.get('xiechao','name')
print(type(res)) #<class 'str'> res = config.getint('xiechao','age')
2、修改
config.remove_section('xiechao') #xiechao整个标题就被删除
config.remove_section('xiechao','age') #删除xiechao下面的age选项
config.write(open('a.ini','w'))
3、增加
config.add_section('xiechao') #增加配置,先加标题
config.set('xiechao','age',18) #添加选项,第一个参数是标题,第二个是k ,第三个是v
config.write(open('a.ini','w'))
day6_python之configparser_模块的更多相关文章
- day--6_python常用模块
常用模块: time和datetime shutil模块 radom string shelve模块 xml处理 configparser处理 hashlib subprocess logging模块 ...
- day6_python序列化之 json & pickle & shelve 模块
一.json & pickle & shelve 模块 json,用于字符串 和 python数据类型间进行转换pickle,用于python特有的类型 和 python的数据类型间进 ...
- npm 私有模块的管理使用
你可以使用 NPM 命令行工具来管理你在 NPM 仓库的私有模块代码,这使得在项目中使用公共模块变的更加方便. 开始前的工作 你需要一个 2.7.0 以上版本的 npm ,并且需要有一个可以登陆 np ...
- node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理
一.一个简单的node程序 1.新建一个txt文件 2.修改后缀 修改之后会弹出这个,点击"是" 3.运行test.js 源文件 使用node.js运行之后的. 如果该路径下没有该 ...
- ES6模块import细节
写在前面,目前浏览器对ES6的import支持还不是很好,需要用bable转译. ES6引入外部模块分两种情况: 1.导入外部的变量或函数等: import {firstName, lastName, ...
- Python标准模块--ContextManager
1 模块简介 在数年前,Python 2.5 加入了一个非常特殊的关键字,就是with.with语句允许开发者创建上下文管理器.什么是上下文管理器?上下文管理器就是允许你可以自动地开始和结束一些事情. ...
- Python标准模块--Unicode
1 模块简介 Python 3中最大的变化之一就是删除了Unicode类型.在Python 2中,有str类型和unicode类型,例如, Python 2.7.6 (default, Oct 26 ...
- Python标准模块--Iterators和Generators
1 模块简介 当你开始使用Python编程时,你或许已经使用了iterators(迭代器)和generators(生成器),你当时可能并没有意识到.在本篇博文中,我们将会学习迭代器和生成器是什么.当然 ...
- 自己实现一个javascript事件模块
nodejs中的事件模块 nodejs中有一个events模块,用来给别的函数对象提供绑定事件.触发事件的能力.这个别的函数的对象,我把它叫做事件宿主对象(非权威叫法),其原理是把宿主函数的原型链指向 ...
随机推荐
- nginx链接末尾自动补全斜杠
放在locaation里边就行 if (-d $request_filename){ rewrite ^(.*[^/])$ $/ permanent;#加斜杠 } 这样,nginx就会进行判断了,如果 ...
- js点击复制文本
// 动态创建 input 元素 var aux = document.createElement("input"); // 获得需要复制的内容 aux.setAttribute( ...
- 2018-11-1-WPF-Main-thread-gets-a-deadlock-when-stylus-input-thread-is-waiting-for-the-window-to-clos...
title author date CreateTime categories WPF Main thread gets a deadlock when stylus input thread is ...
- hadoop-hive查询ncdc天气数据实例
使用hive查询ncdc天气数据 在hive中将ncdc天气数据导入,然后执行查询shell,可以让hive自动生成mapredjob,快速去的想要的数据结果. 1. 在hive中创建ncdc表,这个 ...
- 只需一步,DLA开启TableStore多元索引查询加速!
一.背景介绍 Data Lake Analytics(简称DLA)在构建第一天就是支持直接关联分析Table Store(简称OTS)里的数据,实现存储计算分离架构,满足用户基于SQL接口分析Tabl ...
- System.getProperty()和getenv()
System.getproperty(String name) 获取系统属性 System.getProperties() 获取所有系统属性 System.getenv(String name) 获取 ...
- [Vue CLI 3] @vue/cli-plugin-eslint 源码分析
熟悉 eslint-loader 的同学一般如下配置: 设置一下几项: test : A condition that must be met(一般是处理对应文件的正则) exclude : A co ...
- 使用C3P0和DBUtils
1.导包 2.配置c3p0-config.xml <?xml version="1.0" encoding="UTF-8"?> <c3p0-c ...
- 设置脚本sh
- ns2 错误(_O17 cmd line 1) 解决
重新安装ns2,发现了如下错误: (_o17 cmd line 1) invoked from within "_o17 cmd addr" invoked from within ...