read/write .properties file in a simple line-oriented format
Project description
# Brief
read/write .properties file in line-oriented format
`key=value` per line *through function*.
*the code refers to `java.util.Properties` in Java 1.6.*
# Common Usage
* file I/O:
```python
# input
properties = load(file)
# or update existing dictionary
load(file, properties)
# output
store(file, properties)
```
* custom input:
`class LineReader` read in one key-value data. It skips all comment lines,
blank lines, leading whitespace, and processes multi-line data.
`loadSingle(string)` read each piece of data given above to key-value.
```python
for line in LineReader(file): # each key-value line has no line seperator
key, value = loadSingle(line)
# do something
```
* custom output:
`storeComments(writable, comments, linesep=os.linesep))`
write comment (accept multi-line), can specify the line terminator.
`storeSingle(writable, key, value, sep='=', linesep=os.linesep)`
write one key-value, can specify the seperator and the line terminator.
```python
storeComments(file, 'this is a comment')
storeSingle(file, 'key', 'value')
```
# File Format
normally each line is comment line or a key-value pair.
main features:
* seperate key and value by one of `=`, `:`, ` `, `\t`
* ignore whitespaces leading in a line or around `=` or `:`
* comment line begin with `#` or `!`
* escape unicode by `\uxxxx`
* escape special characters by adding `\`
others:
* data line ends with `\` discard the line break
differences with Java:
* store method will not write datetime comment
# Changelog
#### v0.1.0, 2018-6-7
set up.
read/write .properties file in line-oriented format
`key=value` per line *through function*.
*the code refers to `java.util.Properties` in Java 1.6.*
# Common Usage
* file I/O:
```python
# input
properties = load(file)
# or update existing dictionary
load(file, properties)
# output
store(file, properties)
```
* custom input:
`class LineReader` read in one key-value data. It skips all comment lines,
blank lines, leading whitespace, and processes multi-line data.
`loadSingle(string)` read each piece of data given above to key-value.
```python
for line in LineReader(file): # each key-value line has no line seperator
key, value = loadSingle(line)
# do something
```
* custom output:
`storeComments(writable, comments, linesep=os.linesep))`
write comment (accept multi-line), can specify the line terminator.
`storeSingle(writable, key, value, sep='=', linesep=os.linesep)`
write one key-value, can specify the seperator and the line terminator.
```python
storeComments(file, 'this is a comment')
storeSingle(file, 'key', 'value')
```
# File Format
normally each line is comment line or a key-value pair.
main features:
* seperate key and value by one of `=`, `:`, ` `, `\t`
* ignore whitespaces leading in a line or around `=` or `:`
* comment line begin with `#` or `!`
* escape unicode by `\uxxxx`
* escape special characters by adding `\`
others:
* data line ends with `\` discard the line break
differences with Java:
* store method will not write datetime comment
# Changelog
#### v0.1.0, 2018-6-7
set up.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sine.properties-0.1.0.tar.gz
(11.9 kB
view hashes)
Built Distribution
Close
Hashes for sine.properties-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1484aaff90249dfdbfc8ea4810f0d2a311a56e26003d0993697bc3ba0bb54819 |
|
MD5 | 28b899af2b9b42aa20baf188fb649e8e |
|
BLAKE2b-256 | 0181485da15d05879fd3dac7093e49be76c966d6d24754cf14377969a9fea869 |