Skip to content

Commit

Permalink
doc: Add example usage to README (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
msto authored Apr 1, 2024
1 parent f638405 commit 46b8702
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,38 @@

Dataclass IO.

## Usage

```py
from dataclasses import dataclass
from dataclass_io import DataclassReader


@dataclass
class MyData:
foo: int
bar: str


with DataclassReader(path, MyData) as reader:
for record in reader:
do_something(record.foo)
```


```py
from dataclasses import dataclass
from dataclass_io import DataclassWriter


@dataclass
class MyData:
foo: int
bar: str


with DataclassWriter(path, MyData) as writer:
for i in range(3):
record = MyData(foo=i, bar="something")
writer.write(record)
```

0 comments on commit 46b8702

Please sign in to comment.