python读取配置文件
来源:互联网 发布:国税总局网络 编辑:程序博客网 时间:2024/05/21 19:51
当需要使用python读取配置文件时,需要使用到python的ConfigParser模块。下面举个栗子。
首先创建init格式的配置文件0.init:
[global]id = 0object_x = 0.003[world]id = 12object_x = 0.14
在python中读取并使用配置文件中的内容:
#! /usr/bin/pythonimport ConfigParserconfig = ConfigParser.ConfigParser()config.readfp(open("0.ini"),"rb")object_id = int(config.get("global","id"))object_x = config.get("global","object_x")print type(object_id), object_idprint type(object_x), object_xworld_id = int(config.get("world","id"))world_x = config.get("world","object_x")print type(world_id), world_idprint type(world_x), world_x
输出结果为:
<type 'int'> 0<type 'str'> 0.003<type 'int'> 12<type 'str'> 0.14
阅读全文
0 0
- Python读取ini配置文件
- Python读取配置文件
- python读取配置文件
- 用Python读取配置文件
- Python读取ini配置文件
- python读取配置文件
- python 读取配置文件
- python读取properties配置文件
- Python读取配置文件
- 【Python】配置文件读取
- Python读取配置文件
- python 读取配置文件
- Python读取INI配置文件
- Python 读取配置文件
- python读取配置文件
- python 读取配置文件
- python读取配置文件configparser
- python读取配置文件
- ButterKnife使用详解
- redis队列操作
- @OneToOne
- Java集合---ArrayList的实现原理
- js2
- python读取配置文件
- 多线程之NSThread
- cdh集成kafka,spark2
- Linux笔记 程序非正常退出报错 Segmenttation fault
- Android设置Activity背景为透明style发生的错误
- leetcode#552. Student Attendance Record II
- 一个页面从输入 URL 到页面加载显示完成,这个过程中都发生了什么?
- code
- laravel5 怎么实现事务