Oct-27-2022, 08:14 PM
I have some QIF data in a file, and the 'Date" record needs modifying. The Dates are of the format
D4/7'2004
and they need to be changed to
D04/07/2004
so the code is nearly there. The dates are in MM/DD/YYYY format. The rules for the code need to be if the MM or DD is a length of one char, then add the leading zero. Also I assume the \n is a carriage return or line feed to indicate a record separation.
I also need to write a new file with only the date records modified, so that needs to be added in wherever the print statements are, or similar.
D4/7'2004
and they need to be changed to
D04/07/2004
f = open("ANCU.qif","r") lines = f.readlines() for line in lines: first_char = line[0] if(first_char == "D"): print("Found a date record") print(first_char) new_line = line.replace("'","/") parts = new_line.split("/",2) print(parts) new = "/".join(parts) print(new) else: print("Nope") print(first_char) # closing the file f.close()is producing ..
Quote:Found a date record
D
['D6', '30', '2005\n']
D6/30/2005
Nope
C
Nope
T
Nope
P
Nope
L
Nope
^
Found a date record
D
['D7', '7', '2005\n']
D7/7/2005
Nope
C
Nope
M
Nope
T
Nope
P
Nope
L
Nope
^
so the code is nearly there. The dates are in MM/DD/YYYY format. The rules for the code need to be if the MM or DD is a length of one char, then add the leading zero. Also I assume the \n is a carriage return or line feed to indicate a record separation.
I also need to write a new file with only the date records modified, so that needs to be added in wherever the print statements are, or similar.