Created
November 20, 2019 00:26
-
-
Save xhiroga/6c5a8ac4749d25f5ecbffcfad9e750e4 to your computer and use it in GitHub Desktop.
Pythonでdaataclassのうち、値がNoneの項目を除外して辞書化するスニペット
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dataclasses.asdict( | |
obj, | |
dict_factory=lambda tuples: {tuple[0]: tuple[1] for tuple in tuples if tuple[1] is not None} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment