help:python:data_class
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
help:python:data_class [2020/08/11 14:43] – [Data Class in Python] gerhard | help:python:data_class [2020/08/11 15:02] – [Data Class in Python] gerhard | ||
---|---|---|---|
Line 18: | Line 18: | ||
====== Data Class in Python ====== | ====== Data Class in Python ====== | ||
+ | |||
+ | Create three data classes called a, b and c with a and b contained in c. | ||
+ | |||
+ | |||
+ | Also note the '' | ||
<code python> | <code python> | ||
Line 50: | Line 55: | ||
</ | </ | ||
+ | |||
+ | The ' | ||
+ | |||
+ | Data is then type casted to a dictionary that yields the key/value pairs in the for loop and prints them to the console. | ||
<code json> | <code json> | ||
Line 59: | Line 68: | ||
</ | </ | ||
+ | <WRAP center round tip 60%> | ||
+ | The really cool feature of this approach is the ability to keep on dynamically adding variables and getting the iterator to expose them dynamically without knowing what is in the class when passed between functions or even applications. | ||
+ | |||
+ | This approach also sets up the class for passing on json strings between applications with very little code required to prepare the string. | ||
+ | |||
+ | </ | ||
+ | |||
+ | <code python> | ||
+ | |||
+ | import json | ||
+ | |||
+ | json.dumps(dict(data)) | ||
+ | |||
+ | </ | ||
+ | |||
+ | The resulting output is: | ||
+ | |||
+ | <code json> | ||
+ | ' | ||
+ | |||
+ | </ | ||
help/python/data_class.txt · Last modified: 2020/08/11 15:04 by gerhard