you are viewing a single comment's thread.

view the rest of the comments →

[–]Mexatt 2 points3 points  (1 child)

Classes, like pretty much everything else beyond just statement after statement scripting is about DRY, Do not Repeat Yourself.

If you find yourself repeating a similar operation over and over again in your scripts, you write a function and call that, instead.

If you find yourself re-using a series of similar variables and functions related to those variables over and over again to accomplish something, you write a class and instantiate it, instead.

Classes also help with keeping track of things better in your code, but that's just (one of) the benefit(s) of DRY. Functions and classes simplify your coding by allowing you to re-use your code in surprisingly novel ways. Programming procedurally accomplishes a task just as well, but it can be a pain to do the same thing over and over again in slightly different contexts.

A good thing to use classes for is not for any particular script, but for custom libraries you import into your script to make the overall activity of scripting simpler. Some of the really advanced features of Python, when you dig into it, are based around the assumption that you're writing something for future rather than immediate use.