Oct-28-2022, 10:34 PM
(Oct-28-2022, 10:23 AM)rob101 Wrote: As I had 10 mins spare, I've come up with a possible solution:
Thanks, I added a loop to read the file, code now ..
def format_date(date): for index, item in enumerate(date): if index == 0: month = item.lstrip("D") month = "D" + str(f"{int(month):02d}") elif index == 1: day = str(f"{int(item):02d}") else: year = item.rstrip("\n") return f"{month}/{day}/{year}" f = open("ANCU.qif","r") lines = f.readlines() for line in lines: if line[0] == 'D': date = format_date(line) continue print(date) # closing the file f.close()
Output:Traceback (most recent call last):
File "......search_replace_5.py", line 18, in <module>
date = format_date(line)
File ".....search_replace_5.py", line 5, in format_date
month = "D" + str(f"{int(month):02d}")
ValueError: invalid literal for int() with base 10: ''