Re-formatting a text.file using python

Hi all,

I am quiet new in python, and I wish to have your help with re-formatting a text file. A portion of the input text.file is below:

Date 1936 10 1
CHANGE ‘101’

It mainly contains two keywords: DATE (year month day) and CHANGE (following be a variable like ‘10’ and a number like 1.0). What I want is to have it converted as the text.file below:

Date 1 Oct 1936
CHANGE ‘10’ good 1
CHANGE ‘101’ bad 0.4516

Changes includes: 1. Date reformat. Have the DATE (year month day) to DATE (day month year). And the month to be corresponding words rather than number, say 10 to be Oct. I guess we should have a check function which can assign number 1 to 12 with a right words “Jan, Feb, …Dec”.
2. Add ‘good’ or ‘bad’ after the CHANGE ‘variable’ (eg ‘10’). I have an array of variables (‘10’, ‘210’, ‘12w’, etc) to put ‘good’, while another array of variables (‘101’, ‘112w’, etc.) to put ‘bad’. So whenever the script meet ‘variable’ right after CHANGE, it can check whether this ‘variable’ is in good or bad groups. Then add a string after it.

It would be great if I could have python to do it since I have a long file. Any help or hint would be highly appreciated! Thank you very much!

Hello Andy and welcome to!

It sounds like you need a whole program. We are more able to help someone with a problem in a specific part of their code. This helps people improve their skills in Python as they write the code to perform the task they need.

What’s your experience level with Python?

Have you started to write any code for this process?

If you need someone to write a whole program, you could try or one of the other options on this list of freelance platforms. You can probably have this program written for around $20 (maybe less $ if quality is less important).

1 Like