I have the Property and Properties dataclasses and want to output into a csv format. I took the references from https://pypi.org/project/dataclass-csv/ for csv writer.
@dataclass
class Property:
property_id: str = field(default=None)
property_features: dict[str, str] = field(default_factory=lambda: {
'Property_1': None,
'Property_2': None,
})
@dataclass
class Properties:
Property_list: list[Property] = field(default_factory=list)
output:
p_collection = Properties(Property_list=[Property(property_id='48a7bfa2', property_features={'Property_1': 'tin', 'Property_2': 'Electric blue'})])
To save the p_collection as csv, I tried:
from dataclass_csv import DataclassWriter
with open(output_file_name, 'w') as f:
w = DataclassWriter(f, p_collection, Properties)
w.write()
This errors with ValueError("Invalid 'data' argument. It must be a list") Here Properties is a list of Property. Could you see if I am missing anything?