import os, inquirer, glob, shutil, datetime, pandas, re
from subprocess import *
from typing import List
from inquirer.themes import GreenPassion
from pathlib import Path
Odb_File_Path = str(os.getcwd())
Path = {}
Inp_File_Selected_WOext = ['File_001.inp', 'File_002.inp', 'File_003.inp']
Inp_Short_Names_File = ["Path_1.inp","Path_2.inp","Path_2.inp" ]
for i in range(len(Inp_Short_Names_File)):
Numbers = []
inFile = open(Inp_File_Selected_WOext[i])
outFile = open(Inp_Short_Names_File[i], "w")
keepCurrentSet = False
for line in inFile:
if line.startswith("*"):
keepCurrentSet = False
if keepCurrentSet:
outFile.write(line)
if line.startswith("*Nset, nset=PATH, unsorted"):
keepCurrentSet = True
inFile.close()
outFile.close()
with open(Inp_Short_Names_File[i]) as f:
lines = f.read()
with open(Inp_Short_Names_File[i], "w") as f:
for line in lines:
f.write(re.sub(',', '', line))
with open(Inp_Short_Names_File[i]) as f:
lines = f.read()
for z in lines.split():
if z.isdigit():
Numbers.append(int(z))
with open(Inp_Short_Names_File[i], "w") as f:
for line in lines:
f.write(str(Numbers))
with open(Inp_Short_Names_File[i],"r") as f:
lines = f.readlines()
Path[i] = lines
OutputFile = open(r'output.inp',"w")
OutputFile.write(str(Path))
OutputFile.close
it seems that when I'm extracting the numbers he creates a list correctly, but it writes this list 3 times in each file
The files "File_001.inp" in my code look like this, and I want to copy just the numbers between the 2 *
Text
..
..
...
..
..
*Nset, nset=PATH, unsorted
13, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735
736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751
752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767
3434, 3435, 3436, 3437, 128, 128, 3357, 3358, 3359, 3360, 3361, 3362, 3363, 122, 122, 3243
3244, 3245, 3246, 3247, 121, 121, 112, 112, 3099, 3100, 3101, 3102, 99, 99, 2831, 2832
2833, 2834, 2835, 2836, 2837, 2838, 2839, 2840, 2841, 2842, 2843, 2844, 2845, 2846, 2847, 2848
2849, 2850, 2851, 2852, 2853, 2854, 2855, 2856, 2857, 2858, 2859, 2860, 2861, 2862, 2863, 2864
2865, 2866, 2867, 2868, 2869, 2870, 2871, 2872, 2873, 2874, 2875, 2876, 2877, 2878, 2879, 2880
2881, 2882, 2883, 2884, 2885, 2886, 2887, 2888, 2889, 88, 88, 2506, 2507, 2508, 2509, 2510
2511, 2512, 2513, 2514, 2515, 2516, 2517, 2518, 2519, 2520, 2521, 2522, 2523, 2524, 2525, 2526
2527, 2528, 2529, 2530, 2531, 2532, 2533, 2534, 2535, 2536, 2537, 2538, 2539, 2540, 2541, 2542
2543, 2544, 2545, 2546, 2547, 2548, 2549, 2550, 2551, 2552, 2553, 2554, 2555, 2556, 2557, 2558
2559, 2560, 2561, 2562, 2563, 2564, 72
*Text
....
...
...
..
Text