Warning: This question isn't a duplicate of the old "How do I create a bunch of variables in a loop?" because it uses a special class with arguments. If code actively disrespectful to PEP8 makes your eyes bleed, go no further, traveler!
Ok, I'm writing some code for a graph of objects in a detailed network and I want the code itself to look a particular way. For the purposes of this question, this means that I do not want to write the code such that I am referencing a dictionary with keys generated in a loop that reference instances of my special class. I want to write the code in a minimal way that I am aware is non-Pythonic, yet acceptable to my awful psychological makeup.
So: how should the code for the function instantiate
shown below be written? The idea is that this function instantiates a variable with the name specified using the special class Relay
that has some arguments.
import uuid
def generate_Python_variable_names(
number = 10
):
names = []
while len(names) < number:
name = str(uuid.uuid4()).replace("-", "")
if name[0].isalpha():
names.append(name)
return names
number_relays = 100
for name in generate_Python_variable_names(number = number_relays):
instantiate(name, Relay(configuration = 1)