Python Forum
Loop through a list of string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop through a list of string
#1
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='')
Reply
#2
Cases = ["LMC","NMC,"MMC"]

should be

Cases = ["LMC", "NMC", "MMC"]
Reply
#3
(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
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Loop through a list of string oldtrafford 4 1,487 Mar-24-2022, 05:30 PM
Last Post: deanhystad
  loop for dynamic cut string - cleaner way? korenron 4 1,956 Nov-22-2021, 02:30 PM
Last Post: korenron
  I am trying to reverse a string using loop codinglearner 4 2,188 Sep-28-2021, 10:46 PM
Last Post: Pedroski55
  Convert string to JSON using a for loop PG_Breizh 3 2,988 Jan-08-2021, 06:10 PM
Last Post: PG_Breizh
  Appending to list of list in For loop nico_mnbl 2 2,373 Sep-25-2020, 04:09 PM
Last Post: nico_mnbl
  Append list into list within a for loop rama27 2 2,399 Jul-21-2020, 04:49 AM
Last Post: deanhystad
  String slicing and loop iteration divyansh 9 4,760 Jun-07-2020, 10:29 PM
Last Post: divyansh
  I converted string to 'list', but it doesn't look like a list! mrapple2020 3 3,260 Apr-07-2019, 02:34 PM
Last Post: mrapple2020
  Putting an array for each string that is printed to a loop ClaudioSimonetti 1 2,351 Feb-05-2019, 12:52 PM
Last Post: perfringo
  loop through list or double loop 3Pinter 4 3,456 Dec-05-2018, 06:17 AM
Last Post: 3Pinter

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020