https://github.com/stefantaubert/iterable-serialization
Serialization and deserialization of iterables with elements of type `str` from and to a string; similar to `str.join(...)`.
https://github.com/stefantaubert/iterable-serialization
iterable serialization str
Last synced: over 1 year ago
JSON representation
Serialization and deserialization of iterables with elements of type `str` from and to a string; similar to `str.join(...)`.
- Host: GitHub
- URL: https://github.com/stefantaubert/iterable-serialization
- Owner: stefantaubert
- License: mit
- Created: 2022-03-30T15:33:42.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-04-19T15:44:51.000Z (about 4 years ago)
- Last Synced: 2025-01-31T11:34:38.504Z (over 1 year ago)
- Topics: iterable, serialization, str
- Language: Python
- Homepage:
- Size: 34.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# iterable-serialization
[](https://pypi.python.org/pypi/iterable-serialization)
[](https://pypi.python.org/pypi/iterable-serialization)
[](LICENSE)
Serialization and deserialization of iterables with elements of type `str` from and to a string; similar to `str.join(...)`.
This package aims to be an improved version of:
```python
# serialization
>>> serialized = "|".join(("a", "b", "c"))
>>> serialized
'a|b|c'
# deserialization
>>> deserialized = serialized.split("|")
>>> deserialized
['a', 'b', 'c']
```
It makes it possible to serialize/deserialize an iterable with occurring symbols as separator:
```python
>>> from iterable_serialization import deserialize_iterable, serialize_iterable
# serialization
>>> serialized = serialize_iterable(("a", "b", "c"), "a")
>>> serialized
'aabac'
# deserialization
>>> deserialized = deserialize_iterable(serialized, "a")
>>> tuple(deserialized)
('a', 'b', 'c')
```
With the version above, it would result in a wrong deserialization result:
```python
# serialization
>>> serialized = "a".join(("a", "b", "c"))
>>> serialized
'aabac'
# deserialization
>>> deserialized = serialized.split("a")
>>> deserialized
['', '', 'b', 'c']
```
## Installation
```sh
pip install iterable-serialization
```
## Usage
```python
>>> from iterable_serialization import deserialize_iterable, serialize_iterable
# serialization
>>> serialized = serialize_iterable(("a", "b", "c"), "a")
>>> serialized
'aabac'
# deserialization
>>> deserialized = deserialize_iterable(serialized, "a")
>>> tuple(deserialized)
('a', 'b', 'c')
```