Python标准化 - 使用配置文件
2016-04-18 00:00
531 查看
摘要: Python标准化 - 配置文件
在使用Python进行代码开发的过程中,有一些通用变量建议存放在统一的配置文件中,而此时建议使用ConfigParser实现:
1. 配置文件
2. 示例程序
功能说明:根据输入的直径,计算对应的圆的面积
在使用Python进行代码开发的过程中,有一些通用变量建议存放在统一的配置文件中,而此时建议使用ConfigParser实现:
1. 配置文件
[numbers] N_PI:3.1415926 [messages] M_WELCOME:Welcome to circle area calculator! M_DIA:Please enter the circle diameter: M_RESULT:The circle area is:
2. 示例程序
功能说明:根据输入的直径,计算对应的圆的面积
# coding=utf-8 __metaclass__ = type __author__ = 'dbloop' import ConfigParser l_ConfigFile = r'C:\Python27\configDir\test001\test001.cfg' # 创建配置文件解析对象 l_CP = ConfigParser.ConfigParser() # 解析配置文件 l_CP.read(l_ConfigFile) # 读取配置文件内容 print l_CP.get(section = 'messages',option = 'M_WELCOME') l_dia = int(raw_input(l_CP.get(section = 'messages',option = 'M_DIA'))) print l_CP.get(section = 'messages',option = 'M_RESULT') + \ str(l_CP.getfloat(section = 'numbers',option = 'N_PI') * l_dia ** 2)
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法