dimanche 27 juin 2021

python to organize code to be more modular and generic

I have this loop that builds string out of some parameters, I like to make it more modular in case other parameters are added Currently cant find better idea from what i have now :

my_list = []
separator = "|"
for dd in data_:

    function_that_handle(dd)

    my_list.append(f"'\$}.myapp{separator}{self.container.app_type}'")
    my_list.append(f"'\$}.ip{separator}{self.container..server_ip}'")
    my_list.append(f"'\$}.port{separator}{self.container..server_port}'")
    my_list.append(f"'\$}.name{separator}{db_properties.get('user_name')}'")
    my_list.append(f"'\$}.pass{separator}{self.container.org_password}'")
    my_list.append(f"'\$}.version{separator}{self.container.org_version}'")
    my_list.append(f"'\$}.uuid{separator}{self.container.app_uuid}'")
              

all_config=f"[{','.join(map(str, my_list))}]

The problem is that more parameters can be added so the list can be long. Any idea to make it more organized?

Aucun commentaire:

Enregistrer un commentaire