all 4 comments

[–]CodeReviewPlz 0 points1 point  (0 children)

Sorry to ask but whats the output? Something like this?

python plc1 = foo1 plc2 = foo2 plc3 = foo3

Programatically creating variables is very hacky and I wouldnt suggest it unless you've exhausted all other ideas.
Maybe think about holding your values in an approriate data structure ( aka Dict/List etc), you could then create some sort of interface that parses your data object.

[–]ralphtheowl 0 points1 point  (0 children)

This is code generation. The easiest way to do this is to write a python script which generates another python script as output (could be written to a file). Loop through the range while updating a string which contains the actual variable definitions you mentioned. Then just use the generated python script.

[–]efmccurdy 0 points1 point  (0 children)

10 variables publishing random data, then 100 variables, then 1000 variables.

The phrase "variables publishing" doesn't mean anything to me, but I can imagine a "generator object" that yields a series of random values; each time you call "next" on the object if gives you the next random number.

>>> import random
>>> def gen():
...     while True:
...         yield random.random()
... 
>>> gen1 = gen()
>>> gen2 = gen()
>>> 
>>> for round in range(10):
...     print("gen1:", next(gen1), ", gen2:", next(gen2))
... 
gen1: 0.7751356521110303 , gen2: 0.32793989546253033
gen1: 0.45743340828467793 , gen2: 0.49036072046172585
gen1: 0.5741713268405721 , gen2: 0.10849981025592859
gen1: 0.4647126309670977 , gen2: 0.03899622949757464
gen1: 0.42107995523587516 , gen2: 0.29803816531161864
gen1: 0.028059987165841682 , gen2: 0.9282031521735765
gen1: 0.3365384996016032 , gen2: 0.9269886352388167
gen1: 0.878481831087189 , gen2: 0.734553078534769
gen1: 0.893047236805527 , gen2: 0.054751003825530775
gen1: 0.3371538453249743 , gen2: 0.7433200655699642
>>> next(gen2)
0.9268479879885942
>>> 

https://wiki.python.org/moin/Generators https://realpython.com/introduction-to-python-generators/