Is it a good idea to using class as a namespace in Python

Yes, indeed. You can use Python classes strictly for namespacing as that is one of the special things they can do and do differently than modules. It’s a lot easier to define a class as a namespace inline in a file than to generate more files.
You should not do it without commenting your code saying what it’s for.
Python classes come in a lot of different forms and purposes and this makes difficulty understanding code you have not seen before.

A Python class used as a namespace is no less a Python class than one that meets the perception of what a class is in other languages. Python does not require a class to be instantiated to be useful. It does not require ivars and does not require methods. It is fairly flexible.

Clases can contain other classes too.

Lots of people have their ideas about what is or isn’t Pythonic.
But if they were all worried about something like consistency, they’d push to have things like len() dir() and help() be a method of objects rather than a global function.

Do what works, comment / document it if it isn’t usual or obvious usage.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)