# Config Variables Initialization | Python

I found interesting the way Python's requests library does the status_code data structure initialization (see code here). I am reusing it in a hobby project, but instead of using just one configuration variable I want it to initialize a few of them, code below:

from .models import LookupDict

# Copying Requests data structure and some refactor to data initialization

network_types = LookupDict(name='network_types')
_network_types = {
1: ('GSM',),
2: ('UMTS',),
3: ('LTE',)
}

def _fill(_globals_var, globals_var):
for value, titles in _globals_var.items():
for title in titles:
setattr(globals_var, title, value)

def _init():
for _globals_var, globals_var in [
(_network_types, network_types)
]:
_fill(_globals_var, globals_var)

_init()


So far it's just defined network_types variable but it could initialize as many as you want with both functions _init and _fill.

LookupDict is pretty much the same as the requests implementation (see code here)

With no usage shown, no implementation for LookupDict shown and nothing other than your network type values, this is overdesigned and offers nothing beyond
class NetworkType(Enum):

• I agree with you it is overdesigned if I won't use the purpose this was originally designed for by requests, but I just hate to write this, following your example: NetworkType.GSM.value every time I will use any of the config values Aug 28, 2021 at 18:15
• Wouldn't it just be NetworkType.GSM? That seems pretty straightforward and readable. The value isn't important in enums, so if your use case is to actually use it, just omit the (Enum) from the class. Aug 28, 2021 at 18:28