python confingparser与optparser
2013-10-17 13:59
204 查看
db.conf文件
optpar.py
结果
[cd] host = 127.0.0.1 port = 2206 username = root password = root charset = utf-8
optpar.py
from ConfigParser import ConfigParser import MySQLdb as db from optparse import OptionParser if __name__=="__main__": parser = OptionParser() #---处理命令行参数 parser.add_option('-c', '--conf', dest='conf') (options, args) = parser.parse_args() print options,args co=ConfigParser() co.read(options.conf) s=co.items('cd') print s db=co.get('cd','host') po=co.get('cd','port') co.set('cd','port','2206') co.write(open(options.conf,'w')) print db,po
结果
相关文章推荐
- linux 下长命令的简化(命令别名)
- 如何解读游戏运维工程师这一职位
- linux基础(二)----linux常用命令积累
- linux基础(二)----linux常用命令积累
- Linux下java环境搭建(转)
- CentOs 下 loadrunner 安装linux监控
- 如何理解Linux CPU Load?
- Linux的IO调度器-CFQ
- NS-2安装——Linux平台
- Is supposed to be a reflection of the opinion of lots of the British public
- Linux学习笔记——权限管理(1)
- 网站功能
- 【LINUX下使用ssh登录后bash的命令操作log】
- 脚本学习python和linux-shell和jQuery(javascript)
- Diff 和 Patch 的簡易操作使用筆記 (copied)
- linux中send函数MSG_NOSIGNAL异常消息
- Linux程序调试--查看二进制文件
- linux 之系统时钟和硬件时钟
- linux complete2
- Server Tomcat v6.0 Server at localhost was unable to start within 45 seconds. If the server requires