Python读写,以及修改my.ini文件--针对Python3.0版本
来源:互联网 发布:java中强制类型转换 编辑:程序博客网 时间:2024/06/07 15:40
首先附上 my.ini里面的内容:
[book]
title = the python standard library
author = fredrik lundh
[ematter]
pages = 250
[md5]
value = kingsoft
读取ini文件
__author__ = 'minggxu9' #!/usr/bin/env python# -*- coding: utf-8 -*-'''The ConfigParser module has been renamed to configparser in Python 3.0. The 2to3 tool will automaticallyadapt imports when converting your sources to 3.0.参考网址:http://docs.python.org/library/configparser.html'''import configparser config = configparser.ConfigParser()config.readfp(open('../my.ini')) #可以使用相对路径获取a = config.get("book","author")print(a)
然后追加内容:
__author__ = 'minggxu9'import configparserconfig = configparser.ConfigParser()#写文件config.add_section("book")config.set("book", "title", "the python standard library")config.set("book", "author", "fredrik lundh")config.add_section("ematter")config.set("ematter", "pages", "250")#注意后面的键值必湏为字符串类型# write to fileconfig.write(open('../my.ini', "w"))#写权限然后追加里面的值:__author__ = 'minggxu9'#!/usr/bin/env python# -*- coding: utf-8 -*-import configparserconfig = configparser.ConfigParser()config.read('../my.ini')a = config.add_section("md5")config.set("md5", "value", "1234")config.write(open('1.ini', "r+")) #可以把r+改成其他方式,看看结果:) r+表示以追加的方式,也可以用a ,append最后修改里面的键值:
__author__ = 'minggxu9'#!/usr/bin/env python# -*- coding: utf-8 -*-import configparserconfig = configparser.ConfigParser()config.read('../my.ini')config.set("md5", "value", "kingsoft") #这样md5就从1234变成kingsoft了config.write(open('1.ini', "r+"))
(完,待续)
- Python读写,以及修改my.ini文件--针对Python3.0版本
- python Ini文件读写
- Python读写ini文件
- Python读写ini文件
- MySQL安装后,如何找到my.ini文件以及修改编码方式
- java读写和修改ini文件汇总
- python读写ini文件的模块
- Python中ini文件的读写操作
- INI文件读写--VC6.0
- 关于 MYSQL5.6 版本 my.ini 文件的位置
- 修改mysql数据库my.ini文件不起作用(1)
- mysql性能调优_修改文件my.ini
- my.ini文件
- 跨平台INI文件读写API(C++版本)
- python 读写 .ini 配置文件
- python 读写ini配置文件
- C++针对ini配置文件读写大全
- C++针对ini配置文件读写大全
- 联系各种动态添加表格
- JSP标准标签库之core标签库
- MFC学习总结 (67个技巧)
- sql语句技巧
- 请问机器人定位,国内有那几个牛人?国外又有哪几个牛人
- Python读写,以及修改my.ini文件--针对Python3.0版本
- ASP上传文件到本地服务器(测试成功!);11.10
- RadioGroup音乐按钮工具条
- PHP 优化
- java中有个MessageFormat(使用一下吧)
- 黑马程序员_学习笔记2交通灯系统中面向对象思想的理解以及工厂模式的应用
- android 4.0新特性总结
- MCI mciSendString和mciSendCommand详解
- Python FTP 客户端