Basing on: How do you create different variable names while in a loop?
I created my nameCreator()
function, that within call two other functions.
I would like to ask you, what may cause that it doesn't work as I want it.
after printing nameDict
is see only {}
as result. So as I suppose, the variables aren't even created.
def nameCreator(number):
nameDict={}
for x in range(number):
nameDict["socketMC{0}".format(x)] = socket_creator(arg1, arg2, "analysedSocket{}".format(x))
nameDict["threadMC{0}".format(x)] = threading.Thread(target=MC_analysis, args=(arg1, arg2, nameDict["socketMC{}".format(x)]))
print(nameDict)
return nameDict
I would expect from function to iterate number
times, where in each iteration loop creates 2 objects and at the end return nameDict that can be used somewhere else.
Example:
socketMC0, threadMC0
socketMC1, threadMC1
where socketMC{number}
is a sock object and threadMC{number}
is a thread.
How can I achieve this?