Dataclass IO
Project description
dataclass_io
Read and write dataclasses.
dataclass_io
provides similar functionality to the standard library's csv.DictReader
and csv.DictWriter
, and adds type safety.
Installation
dataclass_io
may be installed via pip
:
pip install dataclass_io
Quickstart
Reading
from dataclasses import dataclass
from dataclass_io import DataclassReader
@dataclass
class MyData:
foo: int
bar: str
with open("test.tsv", "w") as testfile:
testfile.write("foo\tbar\n")
testfile.write("1\tabc\n")
testfile.write("2\tdef\n")
with DataclassReader.open("test.tsv", MyData) as reader:
for record in reader:
print(record.foo)
Writing
from dataclasses import dataclass
from dataclass_io import DataclassWriter
@dataclass
class MyData:
foo: int
bar: str
with DataclassWriter.open("test.tsv", MyData) as writer:
for i in range(3):
record = MyData(foo=i, bar="something")
writer.write(record)
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
dataclass_io-0.2.0.tar.gz
(8.7 kB
view hashes)
Built Distribution
Close
Hashes for dataclass_io-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19e0778d12b41ccd7996c3e5dc054895824a1cdcbf30e23aefb32e6c8068682d |
|
MD5 | 9be53393b5e2b3ccf4d27f29cf5770c9 |
|
BLAKE2b-256 | 151bd7494c4a8bb1a75ac7ceecaea544488b64dc503fdbb30d5869fefcd184bd |