以简单的面向行格式读取/写入.properties文件
sine.properties的Python项目详细描述
简介
以面向行的格式读/写.properties文件key=value
每行通过函数。
代码引用了Java 1.6中的java.util.Properties
。
常用
文件I/O:
# inputproperties=load(file)# or update existing dictionaryload(file,properties)# outputstore(file,properties)
自定义输入:
class LineReader
读取一个键值数据。它跳过所有注释行,
空行、前导空白和处理多行数据。loadSingle(string)
将上面给出的每一条数据读入键值。forlineinLineReader(file):# each key-value line has no line seperatorkey,value=loadSingle(line)# do something
自定义输出:
storeComments(writable, comments, linesep=os.linesep))
写注释(接受多行),可以指定行结束符。storeSingle(writable, key, value, sep='=', linesep=os.linesep)
写一个键值,可以指定分隔符和行结束符。storeComments(file,'this is a comment')storeSingle(file,'key','value')
文件格式
通常每一行是注释行或键值对。
主要功能:
- 按
=
、:
、,
\t
中的一个分隔键和值
- 忽略行首或
=
或:
周围的空格 - 注释行以
#
或!
开头 - 按
\uxxxx
转义Unicode
- 通过添加
\
来转义特殊字符
其他:
- 数据行以^{
结尾}放弃换行符
与Java的区别:
- store方法不会写入datetime注释
更改日志
V0.1.11919-2-9
- 更改为与python3一起运行
V0.1.0,2018年6月7日
- 准备好了。