Python之配置模块ConfigParser】的更多相关文章

http://docs.python.org/2/library/configparser.html http://www.cnblogs.com/sislcb/archive/2008/11/25/1340587.html ConfigParser模块 对应配置文件: [db] db_host = 127.0.0.1 db_port = 3307 db_user = root db_pass = password db_none [concurrent] thread = 10 process…
写项目肯定用的到配置文件,这次学习一下python中的配置文件模块 ConfigParser 安装就不说了,pip一下即可,直接来个实例 配置文件 project.conf [db] host = '127.0.0.1' port = 3306 user = 'root' password = 'redhat' db = 'project' [app] threads = 4 cache_size = 8M [game] speed = 100 脚本 project.py #!/usr/bin/…
1.基本的读取配置文件 -read(filename) 直接读取ini文件内容 -sections() 得到所有的section,并以列表的形式返回 -options(section) 得到该section的所有option -items(section) 得到该section的所有键值对 -get(section,option) 得到section中option的值,返回为string类型 -getint(section,option) 得到section中option的值,返回为int类型,…
ConfigParser ConfigParser包装了配置文件的读取和写入,使得python程序可以更加轻松操作配置文件了.这里的配置文件是指.ini的那种文件,基本格式如下 [section_a] a_key1 = a_value1 a_key2 = a_value2 [section_b] b_key1 = b_value1 b_key2 = b_value2 b_key3 = b_value3 将一个文件分隔成几个section,每个section中又有很多键值对,以这样的方式构建起配置…
这个常见于.conf,.ini等类型的配置文件 下面先看一下如果通过python生成一个.ini文件 import configparser #2.x is ConfigParserconfig = configparser.ConfigParser() #先生成一个对象config["DEFAULT"] = {'ServerAliveInterval': '45', 'Compression': 'yes', 'CompressionLevel': '9'}'''config[&qu…
import ConfigParser //实例化cf = ConfigPraser.ConfigPraser()cf.read("配置文件") //获取所有sections.也就是将配置文件中所有“[ ]”读取到列表中s= cf.sections() //获取指定section 的options.即将配置文件某个section 内key 读取到列表中o = cf.options("db") //获取指定section 的配置信息v = cf.items("…
OS模块 提供对操作系统进行调用的接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname")  改变当前脚本工作目录:相当于shell下cd os.curdir  返回当前目录: ('.') os.pardir  获取当前目录的父目录字符串名:('..') os.makedirs('dirname1/dirname2')    可生成多层递归目录 os.removedirs('dirname1')    若目录为空,则删…
python常用模块-配置文档模块(configparser) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. ConfigParser模块用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser.类似于apache和mysql的配置文件就用这个模块生成的. 一.创建配置文件 #!/usr/bin/env python #_*_coding:utf-8_*_ #@author :yinzhengjie #blog:http://…
一.读取 read(filename) 直接读取ini文件内容  sections() 得到所有的section,并以列表的形式返回 options(section) 得到该section的所有option  items(section) 得到该section的所有键值对  get(section,option) 得到section中option的值,返回为string类型  getint(section,option) 得到section中option的值,返回为int类型 二.写入 add_…
hashlib模块 Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 什么是摘要算法呢?摘要算法又称哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度固定的数据串(通常用16进制的字符串表示). 摘要算法就是通过摘要函数f()对任意长度的数据data计算出固定长度的摘要digest,目的是为了发现原始数据是否被人篡改过. 摘要算法之所以能指出数据是否被篡改过,就是因为摘要函数是一个单向函数,计算f(data)很容易,但通过digest反推data却非常困…