1
sheetData = {'ANSYS_Export': [['Bolt Pretension 33', [[False, 'Time [s]', '1.', '2.', '3.'], 
[True, 'Bolt Pretension 33 (Working Load) [N]', '0.', '1.29e+005', '1.599e+005'], 
[True, 'Bolt Pretension 34 (Working Load) [N]', '0.', '1.29e+005', '1.5996e+005'], 
[True, 'Bolt Pretension 35 (Working Load) [N]', '0.', '1.29e+005', '1.5993e+005']]]]}

s = sheetData["ANSYS_Export"][0]
perc = sheetData["ANSYS_Export"][0]

for x in range(len(s[1])):
    if x == 0:
        continue
    y = 3
    while y < len(s[1][x]):
        z = float(s[1][x][y])/float(s[1][x][3])
        perc[1][x][y] = z
        print(perc[1][x][y])
        y += 1

Hi everyone! I don´t have a deep experience in programming since I am a mechanical engineer, but I like to automate stuff at work. In this case, I am trying to obtain 2 different lists (s and perc), the second one containing percentages of some values of the first by iteration. I have a problem though. If I print the variable z before assigning it to perc[1][x][y], I get the number I am looking for, which is a percentage of 1.29e+005/1.599e+005 for example. However, after the line perc[1][x][y] = z, the result is totally different and even the lists s and perc get corrupted. I appreciate if someone could help me get the two lists as I am planning to instead of the result I am obtaining. Thanks!

quamrana
  • 37,849
  • 12
  • 53
  • 71
Enrique BV
  • 11
  • 1
  • The reason this happens is because `perc` refers to the list itself, so when you assign `z` to it, you are actually changing the contents of `sheetData`. Remove the assignment `perc = sheetData["ANSYS_Export"][0]` – Alex P Oct 31 '22 at 19:51
  • Thanks. Your input was very helpful. – Enrique BV Oct 31 '22 at 22:53

0 Answers0