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

Alan Gauld alan.gauld at yahoo.co.uk
Sun Mar 29 06:56:21 EDT 2020


On 29/03/2020 00:05, Vazquez, Juliana Mary wrote:

We won't do your assignment for you but will try to help.
However, it's not clear what you want help with. Which part of the
assignment is proving difficult?

> Your task is to process each record in a file named “punned_result.txt (see attached) 

Do you know how to read a text file?

and convert it into the following format:

And do you know how to print formatted text?


> –[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.

You can use a format string to gather all the fields together then inset
the values from variables.


> –You may want to use if/elif/else structure inside a while statement

Are you familiar with if/elif/else structures?

Do you know how to use a while loop?


>  to test the first two characters in each line 

Do you know how to extract the first two characters from a line of text?

> Please help me work through this problem!
If you make clear to us what you need made clear then we can help you
further.

Incidentally the file you attached seems to contain patient records
with real email addresses etc. You have just posted these to several
hundred people on the internet.

I suspect that is a breach of data protection legislation.
Please take care of personal data. (Of course the data may have
been anonymized before you got it, but it doesn't look like it!)

It's also far more than was necessary to illustrate the file format.
Just three or four records worth would have been sufficient, and you
could have edited the contents to remove personal data. Some people pay
for their data by the byte...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list