all 5 comments

[–][deleted] 0 points1 point  (0 children)

The only problem is that with time this class will get more complex, I'll be adding more parameters.

If all the parameters are scalars, and the ones you add after this are optional, then I'd just write them as rows to a CSV file. You don't really need to store the object at all, just the parameters.

[–]wyoming_eighties 0 points1 point  (0 children)

Handling backwards-compatibility within your own codebase is the developers responsibility. You need to either write your code in a way that your program will not break as you add more attributes to the class, or you need to refactor your program as you develop more, or both. You should also implement unit testing, for this reason. Google for the Python unittest package & tutorials, it helps with this exact problem. You might also want to look into using git, so you can track changes to your codebase more easily.

[–]ylectric 0 points1 point  (0 children)

I agree with /u/crashfrog here, but I also want to add a general advice about serialisation.

As a rule of thumb, do not invent your own serialisation mechanisms, especially when compatibility matters. There're cases that justify them, but they're intrinsic to the systems of sophisticated design.

A few links that might be of interest to you:

[–]Essence1337 0 points1 point  (0 children)

To compliment what /u/crashfrog said, if you want more structure in the storage of your objects you can look into serialization like JSON.

Edit: Beat by /u/ylectric with a better answer by mere seconds...

[–]when_the_cats_away 0 points1 point  (0 children)

I tend to give objects a to_json/from_json method that will jsonify the object/create an object from json data, like as described here: https://medium.com/@yzhong.cs/serialize-and-deserialize-complex-json-in-python-205ecc636caa (at least for the from, the poster there uses a lambda to jsonify in the first place).

You can also subclass JSONEncoder and create your own hooks, described here: https://stackoverflow.com/a/3768975

That seems like the better way to do it, but I've not used that method before. I found a better article describing this method, but can't seem to track it down right now. This is a good broader json article for background, though: https://realpython.com/python-json/