Global state goes in modules (and functions and classes are just as much global state, loaded at the start). Then store data where it makes sense to your application. Use modules to collect functionality into logical units.Use classes as blueprints for objects that model your problem domain.Modules can contain more than just one class however functions and any the result of any other Python expression can be globals in a module too. You can manipulate those attributes as needed (add, remove and update), but take into account that these still form the global namespace for all code defined in that module.įrom a Java perspective, classes are not all that different here. Modules can't do any of this, modules are essentially singleton instances of an internal module class, and all their globals are attributes on the module instance. Classes support inheritance, metaclasses, and descriptors. There are huge differences between classes and modules in Python.Ĭlasses are blueprints that allow you to create instances with attributes and bound functionality.
0 Comments
Leave a Reply. |