Skip to main content

Python classes with only one instance: When to create a (single) class instance and when to work with the class instead?

Given a Python class which will be instantiated only once, i.e. there will be only one object of the class. I was wondering in which cases it makes sense to create a single class instance instead of working directly with the class instead.

There is a similar question, but it has a different focus:

  1. it is about grouping global variables and functions into a class and
  2. It isn't Python-specific. The latter means it does not consider the fact that (in Python) classes are objects too.
langlauf.io
  • 261
  • 1
  • 2
  • 6