Hello there,
Sorry, unfortunately python parsing is not my main activity, it does not print the last block of the statement.
i should get:
*elset, elset=top_s1
1, 2, 3, 4
*surface, name=top, type=element
top_s1
If i add in the test2 file a line such as *surface, name=bot, type=element then it does print it, what can i change in order to fix it
zip file contains the input file
#!/usr/bin/env python
import os
import sys
import re
import fileinput
import math
surfaceFound = False
f=open("test2.inp","r")
text = f.readlines()
f.close()
e1 = []; e2 = []; e3 = []; e4 = []; e5 = []; e6 = []
s1 = []; s2 = []; s3 = []; s4 = []; s5 = []; s6 = []
elsurf={}
set_name = ""
otherLine = []
finalSet=[]
final_block=[]
elsetName=""
lineTrik = []
for index, lines in enumerate(text):
nline = lines.strip()
lineTrik.append(lines)
surface = "*SURFACE" in lines.strip()
element = "TYPE = ELEMENT" in lines.strip()
digit = lines.strip().split(",")[0].isdigit()
under = lines.strip().startswith("_")
stopParse = "*End Part" is lines.strip()
HM = lines.strip().startswith("**HM")
HW = lines.strip().startswith("**HW")
S1 = lines.strip().endswith("S1")
S2 = lines.strip().endswith("S2")
S3 = lines.strip().endswith("S3")
S4 = lines.strip().endswith("S4")
S5 = lines.strip().endswith("S5")
S6 = lines.strip().endswith("S6")
if surface:
starSurf = nline.split(",")[0].strip()
nameSurf = nline.split(",")[1].split("=")[1].strip()
typeSurf = nline.split(",")[2].strip()
elsetName = nline.split(",")[1].split("=")[1].strip()
surfaceFound = False
for set_name in elsurf.keys():
finalSet.append("*elset, name = %s_%s\n" % (card_name, set_name))
for line in [elsurf[set_name][i*16:(i+1)*16] for i in range(0,(len(elsurf[set_name])/16)+1)]:
if line:
eset = ",".join(line).strip()
finalSet.append("%s\n" % (eset))
final_block.append("%s_%s, %s\n" % (card_name, set_name, set_name))
elsurf={}
(this_card_name, card_type) = (nameSurf, element)
if this_card_name and element:
surfaceFound = True
card_name = elsetName
surfType = typeSurf
final_block.append("*surface, name=%s, %s\n" % (card_name, surfType))
elif (S1 or S2 or S3 or S4 or S5 or S6) and under == False:
surfaceFound = True
value = nline.strip().split(",")[0].strip()
key = nline.strip().split(",")[1].strip()
items = elsurf.setdefault(key, [])
items.append(value)
elif under:
underLine = nline
final_block.append("%s\n" % underLine)
elif stopParse:
endParse = nline
final_block.append("%s\n" % endParse)
elif HM or HW:
pass
else:
other = nline
otherLine.append("%s\n" % other)
for i in otherLine:
print i.strip()
for i in finalSet:
print i.strip()
for i in final_block:
print i.strip()