79544615

Date: 2025-03-30 12:58:45
Score: 1
Natty:
Report link

Looks like you are parsing CSV data. Try to use csv.reader and rewrite file reading section this way:

import csv

# ...

for i in range(nbr_files):
    param_file = "./param_file_no_{0:0>9d}.txt".format(i)
    with open(param_file, 'r') as f:
        for row in csv.reader(f):
            [param1, param2_txt, param3, param4_txt, param5_txt] = row
            # ...

Also you could try to use Pandas or Polars for this, which are very optimized for column-based data and provide handy methods for working with CSV:

https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html

https://docs.pola.rs/api/python/dev/reference/api/polars.read_csv.html

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Oleg Rimko