The task is as follows. The file is read line by line and as soon as the numbers come across in a pattern, they are multiplied and written into place. Simply put, I need to multiply all the numbers from the pattern by a constant. for example, the lines in the file:
values( " 2.326, 2.358, 2.418, 2.481, 2.601, 2.807",\ " 2.348, 2.379, 2.439, 2.503, 2.622, 2.828"); It is necessary to multiply all the numbers in the file by "k"
file = open("txt.txt","r") for line in file: fix_line = re.sub(r'(\d+\.\d+)', '???*k', line) Tried to do through re.sub to replace in line, but stopped on how to arrange a replacement. How to capture each number and replace it with a new number, differing by the coefficient "k". Maybe there is a simpler approach to replacing numbers?