Timeline for Using class attributes as globals in Python - is there a catch?
Current License: CC BY-SA 4.0
4 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 22, 2022 at 22:30 | comment | added | Alexander |
The object-based approach is definitely the way to go. The AppState class makes it really clear what the result of parsing arguments should be, and what's necessary for loading the app's configuration
|
|
| Dec 1, 2022 at 15:14 | comment | added | Jasmijn |
The first example should include global ARGS, CONF as the first line of main. Currently, ARGS and CONFG (sic) are local variables inside main, independent of the globals of the same and similar name. In other functions, ARGS and CONF would still be None.
|
|
| Nov 29, 2022 at 15:51 | comment | added | Alias_Knagg | Tanks! Pylint will complain 'redefined-outer-name' for the first version and complain about the 'global' statement if I use that, but the initial idea was just to prefix all my globals for readability and then a "real prefix" seemed better than just a convention. The dataclass example is something I will have to look into more closely. Especially if you tell me this is a common pattern. But why use an instance when the class will suffice? | |
| Nov 29, 2022 at 13:24 | history | answered | amon | CC BY-SA 4.0 |