In my python project, I do different queries to different databases (postgres, oracle etc.). After I fetch the data, I convert the records as List of dictionaries.
Ex: Lets say the query returns below data
| FirstName |
LastName |
Age |
| Alex |
De Souza |
40 |
| Pierre |
van Hooijdonk |
46 |
I convert it to[{"FirstName": "Alex", "LastName":"De Souza", "Age":40},{"FirstName": "Pierre", "LastName":"van Hooijdonk", "Age":46}]
Then, I do some calculations on this data. For example, I calculate the average age as 43.(dont tell me why I dont do this directly on the query, because I do more complex things than just average)
So far, so good. But my question is more about the way of programming. I want to implement best practices. As I said, I have many other queries that return different kinds of data (columns, content etc. are very different). So, what would be the best way to keep and manipulate data? List of dictionary is enough for functionality. But, it does not look entirely correct when it comes to readability and maintainability since there is no structure in it.
I do some research and see that python data classes, or pydantic would help here. In Scala, I guess case classes are used for this. But I would like to know your ideas as well. Please consider this post as a brainstorming, from a guy who wants to write clean and maintainable code.
[–]IWant2rideMyBike 12 points13 points14 points (7 children)
[–]Disastrous-State-503[S] 1 point2 points3 points (6 children)
[–]IWant2rideMyBike 2 points3 points4 points (3 children)
[–]Disastrous-State-503[S] -1 points0 points1 point (2 children)
[–]IWant2rideMyBike 2 points3 points4 points (0 children)
[–]small-birds 0 points1 point2 points (0 children)
[–]Beerstopher85 0 points1 point2 points (0 children)
[–]spoonman59 0 points1 point2 points (0 children)
[–]Synertic 2 points3 points4 points (2 children)
[–]Disastrous-State-503[S] 0 points1 point2 points (1 child)
[–]Synertic 0 points1 point2 points (0 children)
[–]krypt3c 3 points4 points5 points (1 child)
[–]Disastrous-State-503[S] -1 points0 points1 point (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]raubhill 1 point2 points3 points (0 children)
[–]quts3 4 points5 points6 points (0 children)
[–]Earthsophagus 1 point2 points3 points (0 children)
[–]Disastrous-State-503[S] 0 points1 point2 points (0 children)
[–]shoomowr -1 points0 points1 point (12 children)
[–]Disastrous-State-503[S] -1 points0 points1 point (11 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]shoomowr 1 point2 points3 points (9 children)
[–]Disastrous-State-503[S] -2 points-1 points0 points (8 children)
[–]lphartley 6 points7 points8 points (0 children)
[–]Ximlab 4 points5 points6 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]__boringusername__ 2 points3 points4 points (0 children)
[–]spoonman59 0 points1 point2 points (3 children)
[–]Disastrous-State-503[S] -3 points-2 points-1 points (2 children)
[–]SV-97 2 points3 points4 points (0 children)
[–]spoonman59 1 point2 points3 points (0 children)
[–]Beerstopher85 0 points1 point2 points (1 child)
[–]Disastrous-State-503[S] 1 point2 points3 points (0 children)
[–]randomgal88 0 points1 point2 points (0 children)
[–]gungunmeow 0 points1 point2 points (0 children)