2 ms·
You wouldn't, and good for you having recognized that. :) There are always exceptions to rules though. Perhaps your code is stateless consumer of an api, but yo
by bjourne 8y ago
You wouldn't, and good for you having recognized that. :) There are always exceptions to rules though. Perhaps your code is stateless consumer of an api, but you want to store your username and api key somewhere, so why not in a class? Perhaps you want to create a large number of namespaces and it is more convenient to use static stateless classes than create one new file for each namespace? Some programmers also shy away from module-level variables because to set them in the same module that they are defined requires using the global keyword.
Classes also has some extra trickery over modules which you can use and abuse. Such as __getattr__ and __getitem__.