[Tutor] Python Help: Converting a text file into a specified format

Sibylle Koczian nulla.epistola at web.de
Sun Mar 29 06:55:45 EDT 2020


Am 29.03.2020 um 01:05 schrieb Vazquez, Juliana Mary:
> Your task is to process each record in a file named “punned_result.txt (see attached) and convert it into the following format:
> 
> –[2] Brandt, Mary D; London, Jack E. “Health Informatics Standards: A User’s Guide.” Journal of AHIMA 71, no. 4 (2000): 39-43.
> 
> 1.    You are required to list all the author names [last_name, first_name initial]
> 
> 2.    The content in the quotation is the title of the article
> 
> 3.    Here [2] is the order of the record, 71 is the volume, 4 is the issue number, 2000 is the year of publication, and 39-43 is the start and end pages of the article in that issue of the journal.
> 
> Hints:
> 
> –You may want to use if/elif/else structure inside a while statement to test the first two characters in each line so that you can determine whether you need the info in that line or not.
> 
> 
> 
> Please help me work through this problem!
> 

Which parts do you know how to do, which parts are difficult?

There is quite a big part that doesn't need any coding: examining your 
data file and the format you want to get from it. I'd tend to work 
through that first of all.

- How are the records separated?

- Which fields (with which short names at the beginning of the line) 
contain data you need and where does this data belong in the finished 
citation?

- Can you use these fields as is or do you need to pick parts out of them?

- What about the lines that start with whitespace?

When all this is cleared up: where do you need help with coding?

- Do you know how to open the file and read it line by line?

- Does the hint about using a if/elif/else structure inside a while loop 
help you structure the main part of your code or is it just another riddle?

- Do you know how to take the first two characters of the line (or the 
first word - some of the field names have more than two characters) and 
the rest?

- Do you know how to pick the right parts out of field contents if 
that's necessary?

- Do you know how to reassemble the necessary data in the format you 
need, including the record order?

- Do you know how to write the end results into a new text file?

If some of these questions are very silly, ignore them. If they are 
unclear, tell us. We can't know what is easy for you and what isn't.

Greetings
Sibylle



More information about the Tutor mailing list