# Python Variable name using string Concat

**URL:** <https://forum.inductiveautomation.com/t/python-variable-name-using-string-concat/9461>\
**Category:** Ignition\
**Created:** [December 19, 2014, 6:44am UTC](https://forum.inductiveautomation.com/t/python-variable-name-using-string-concat/9461 "2014-12-19T06:44:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhananjay\_vichare](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dhananjay_vichare/32/74712_2.png) [@dhananjay\_vichare](https://forum.inductiveautomation.com/u/dhananjay_vichare)\
**Post date:** [December 19, 2014, 6:44am UTC](https://forum.inductiveautomation.com/t/python-variable-name-using-string-concat/9461/1 "2014-12-19T06:44:37Z")

</div>

I am using below code to construct the variable name using “String Concat” and get the value of the constructed variable. Is it possible?

Code :  
[i]# Min values  
ThresholdMinId0 = event.source.parent.getComponent(‘Numeric Text Field 29’).doubleValue  
ThresholdMinId1 = event.source.parent.getComponent(‘Numeric Text Field 32’).doubleValue  
ThresholdMinId2 = event.source.parent.getComponent(‘Numeric Text Field 34’).doubleValue  
ThresholdMinId3 = event.source.parent.getComponent(‘Numeric Text Field 36’).doubleValue

# Max values

ThresholdMaxId0 = event.source.parent.getComponent(‘Numeric Text Field 29’).doubleValue  
ThresholdMaxId1 = event.source.parent.getComponent(‘Numeric Text Field 32’).doubleValue  
ThresholdMaxId2 = event.source.parent.getComponent(‘Numeric Text Field 34’).doubleValue  
ThresholdMaxId3 = event.source.parent.getComponent(‘Numeric Text Field 36’).doubleValue

for i in range(4):  
IdFound = system.db.runScalarQuery("SELECT Id from table\_thresholds where Id = " + “’” + str(i) + “’”)  
ThresholdMinValue = Value(“ThresholdMinId%s”) %i  
ThresholdMaxValue = “ThresholdMaxId%s” %i  
  print ThresholdMinValue, ThresholdMaxValue[/i]

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 19, 2014, 11:13am UTC](https://forum.inductiveautomation.com/t/python-variable-name-using-string-concat/9461/2 "2014-12-19T11:13:13Z")

</div>

Hi Dhananjay,

This is something that would actually be better handled by a list:

[code]#Initialize Lists  
ThresholdMinId=ThresholdMaxId=[0.0]\*4

# Min values

ThresholdMinId[0] = event.source.parent.getComponent('Numeric Text Field 29').doubleValue  
ThresholdMinId[1] = event.source.parent.getComponent('Numeric Text Field 32').doubleValue  
ThresholdMinId[2] = event.source.parent.getComponent('Numeric Text Field 34').doubleValue  
ThresholdMinId[3] = event.source.parent.getComponent('Numeric Text Field 36').doubleValue

# Max values

ThresholdMaxId[0] = event.source.parent.getComponent('Numeric Text Field 29').doubleValue  
ThresholdMaxId[1] = event.source.parent.getComponent('Numeric Text Field 32').doubleValue  
ThresholdMaxId[2] = event.source.parent.getComponent('Numeric Text Field 34').doubleValue  
ThresholdMaxId[3] = event.source.parent.getComponent('Numeric Text Field 36').doubleValue

for i in range(4):  
IdFound = system.db.runScalarQuery("SELECT Id from table\_thresholds where Id = '" + str(i) + "'")  
ThresholdMinValue = ThresholdMinId[i]  
ThresholdMaxValue = ThresholdMaxId[i]  
print ThresholdMinValue, ThresholdMaxValue  
[/code]

A brief explanation of the first line-- something I just learned this morning while thinking this through! 😃 [0.0]\*4 returns a list four elements long, each with a value of 0 (0.0 coerces it to float) This way, you can predefine the size of the list. ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")

---

<div class="post-metadata">

**Author:** ![dhananjay\_vichare](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dhananjay_vichare/32/74712_2.png) [@dhananjay\_vichare](https://forum.inductiveautomation.com/u/dhananjay_vichare)\
**Post date:** [December 24, 2014, 4:11am UTC](https://forum.inductiveautomation.com/t/python-variable-name-using-string-concat/9461/3 "2014-12-24T04:11:26Z")

</div>

Thanks JordanCClark,  
😃
