a = 1.1 b = 1.5 with open("sources.reg", "r") as file, open("sources_bkg.reg", "w") as bkg: for line in file.readlines(): vals = line.split(",") RA = vals[0].split("(")[1] DEC = vals[1] if vals[0][0] == "c": R1 = R2 = float(vals[2][:-3]) DIR = "0.00)\n" mag = vals[2][-3] else: R1 = float(vals[2][:-1]) R2 = float(vals[3][:-1]) DIR = vals[4] mag = vals[2][-1] src = f"ellipse({RA},{DEC},{R1 * a:.3g}{mag},{R2 * a:.3g}{mag},{DIR}" bkg_line = f"ellipse({RA},{DEC},{R1 * b:.3g}{mag},{R2 * b:.3g}{mag},{DIR[:-1]}" bkg.write(bkg_line + "*!" + src)