configrw是一个基于键值或ini结构的简单读写器配置文件。

configrw的Python项目详细描述


配置w

configrw是一个简单的python模块,它根据键值或ini结构读写配置文件。

主要功能

    最大保存源文件(缩进、空格、注释等)的格式设置
  • 支持非节(用于访问基于键值的简单配置文件)
  • 在节中的任意字符串上插入选项
  • 支持选项的多个值
  • 支持没有值的选项
  • 支持部分中的评论
  • 支持选项、值的缩进
  • 安全文件重写。写入时使用*.new file,然后重命名为原始文件名

安装

安装包到用户python库目录:

$ pip install --user configrw

或者可以将包安装到python库的全局系统目录(不推荐):

$ sudo pip install configrw

文档

您可以在readthedocs找到有关如何使用configrw的完整手册

快速启动

在下面的示例中,我们将使用以下ini文件:

# This is commentthis is option=this is valuesecond option=-100[ SECTION1 ] # commentoption1=100    option2 = 200    # comment    option3 = 1.2[ section2 ]param1='str'    param2 = 0 # comment    parameter_without_value[section3]extensions=        # comment1        ext1        # comment2        ext2        ext3

进入非截面积

如果要使用配置文件的简单键值,则需要此功能

fromconfigrwimportConfigconfig=Config.from_file('/path/to/file')section=config[None]# Getting non-sectionvalue=section['this is option']# Getting the valuesection['this is option']=None# Setting the valuedelsection['second option']# Deleting the option

进入分区

如果要使用ini配置文件,这是必需的功能

value=config['SECTION1']['option2']# Getting the valueconfig['SECTION1']['option2']=0# Setting the valueconfig['SECTION1']['option3']=300# Adding new option to sectionconfig['section3']['extensions'].append('ext4')# Adding new value to multiple valuesconfig['section3']['extensions'].insert('ext0',0)# Inserting new valueconfig['section3']['extensions'][0]='extension0'# Changing single value of multiple valuesconfig.write('/path/to/file')# Saving config to file# Render config to screenforlineinconfig.to_text():print(line)

更改后的ini文件:

# This is commentthis is option[ SECTION1 ] # commentoption1=100    option2 = 0    # comment    option3 = 300[ section2 ]param1='str'    param2 = 0 # comment    parameter_without_value[section3]extensions=        extension0        # comment1        ext1        # comment2        ext2        ext3        ext4

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在Android上的可访问文件夹中创建文件?(非根)   tomcat Unix脚本未使用Process Runtime在Java中运行   模拟器中的java Android AudioTrack速度异常   java是否创建具有特定@ConditionalOnProperty的注释?   java如何使用json数据从gridview中的URL加载图像?(类别和子类别)   ConcurrentHashMap的java锁定值对象   如何在具有额外属性的Java枚举上执行Javadoc?   java如何修复SocketException连接重置问题?   无附加表的java JPA实体继承   java Android应用程序在启动屏幕后崩溃   java如何将Arraylist保存到文件?   java restTemplate从restfull Web服务获取文件数组   java活动带布局隐藏导航栏   socket未接收任何内容的java BufferedReader