Comments (2)
Hi @hhoeflin , thank you so much.
Could you provide me with some examples of this use case?
Correct me if I'm wrong, the scenario that you are describing is that you want to modify a value while reading it from the CSV file, is that right?
If that's the case, would work to implement that in the __post_init__
method of the data class?
For example, let's say I always want to multiply the numbers I read from a CSV by 2, I could do something like:
CSV:
val
2
Code:
from dataclasses import dataclass
from dataclass_csv import DataclassReader
@dataclass
class Number:
val: int
def __post_init__(self):
self.val = self.val * 2
def main():
with open("numbers.csv") as f:
reader = DataclassReader(f, Number)
for number in reader:
print(number)
if __name__ == "__main__":
main()
Output:
Number(val=4)
from dataclass-csv.
from dataclass-csv.
Related Issues (20)
- datetime fields with default values trigger an error HOT 2
- Does not support __future__.annotations
- Support Optional fields HOT 1
- DataclassWriter HOT 3
- Support frozen dataclasses HOT 1
- Populate dataclass fields in their order with row data HOT 2
- TypeError: 'module' object is not callable referring to "field_type(value)" HOT 1
- Feature Request: Support custom field types HOT 1
- Default values are passed to their constructor HOT 2
- Override constructor with transformation function HOT 15
- Report mapping non-existant column HOT 2
- Automatically generate candidate dataclass HOT 4
- AttributeError: 'str' object has no attribute '__dict__' HOT 7
- Type annotations for *args and **kwds HOT 2
- Allow NULL values more conveniently, and fix README TypeError: non-default argument 'age' follows default argument HOT 2
- Dateformat decorator does not apply to DataclassWriter HOT 4
- DeprecationWarning for distutils package HOT 3
- Cannot read a nested dataclass HOT 2
- Support to split object properties to separate columns.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dataclass-csv.