a = open('../blendswapdrums2-simplified.obj').read() b = a.split('\no ') c = ['o ' + i for i in b[1:]] def normalize(block, offset): u = block.split('\n') vertices = [i for i in u if len(i) >= 2 and i[:2] == 'v '] faces = [i for i in u if len(i) >= 2 and i[:2] == 'f '] def normalize_face(i): _, p, q, r = i.split(' ') return f'f {int(p)-offset} {int(q)-offset} {int(r)-offset}' normalized_faces = [normalize_face(i) for i in faces] normalized_block = '\n'.join(vertices + normalized_faces) new_offset = offset + len(vertices) return normalized_block, new_offset offset = 0 for i in c: fnam = i[2:i.index('\n')] content, offset = normalize(i, offset) print(offset) with open(fnam + '.piece', 'w') as f: f.write(content) # % echo *.piece # '{' + ', '.join(f'"{i}"' for i in t) + '}' # t=s.split(' ')