Python Forum

Full Version: Loop through a list of string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have this code and i want to loop through the number of cases in the list "Cases". here i put an example with 3 elements in the list.
how can I parameter the last line of the code (xyDataNames='RF : LMC,RF : NMC,RF : MMC', trueName='')
 
Number_FEA = 3
Cases = ['LMC', 'NMC', 'MMC']   
import sys
sys.path.insert(46, r'c:/SIMULIA/EstProducts/2021/win_b64/code/python2.7/lib/abaqus_plugins/excelUtilities')
import abq_ExcelUtilities.excelUtilities
abq_ExcelUtilities.excelUtilities.XYtoExcel(xyDataNames='RF : LMC,RF : NMC,RF : MMC', trueName='')
I tried this code with tuple, but it didn't work :

a = ['RF : %s' %Cases[k] for k in range(Number_Fea)]
b = [v for v in a]
import sys
sys.path.insert(46, r'c:/SIMULIA/EstProducts/2021/win_b64/code/python2.7/lib/abaqus_plugins/excelUtilities')
import abq_ExcelUtilities.excelUtilities
abq_ExcelUtilities.excelUtilities.XYtoExcel(xyDataNames=tuple(b), trueName='')
Cases = ["LMC","NMC,"MMC"]

should be

Cases = ["LMC", "NMC", "MMC"]
(Feb-15-2022, 01:56 PM)Axel_Erfurt Wrote: [ -> ]Cases = ["LMC","NMC,"MMC"]

should be

Cases = ["LMC", "NMC", "MMC"]

I corrected that in my post. In my code it was correct, but the code doesn't work with the tuple I used
Can make it like this,it need to be string and not tuple.
>>> Cases = ['LMC', 'NMC', 'MMC']  
>>> str_arg = 'RF : {},RF : {},RF : {}'.format(*Cases)
>>> str_arg
'RF : LMC,RF : NMC,RF : MMC'
Then call it like this.
XYtoExcel(xyDataNames=str_arg, trueName='')
Dos the they still use Python 2.7 and not and update to Python 3?
python2.7/lib/abaqus_plugins