Python3 write to file

Re: Python3 write to file

von Richard Lobb -
Anzahl Antworten: 0

Here's a screen shot from one of our questions that asks students to read one file and write another file with the order of lines in the file reversed.

Screenshot of file-writing question

As you can see, the test in this case just calls the student's function then checks to see if the new file exists and, if so, prints its contents.

This doesn't however check if the student has closed the file or not.  I haven't found an easy way of doing that. A simple hack is to check for the existence of a substring .close() within the student's code but it's not failsafe - the close() might be of an unrelated file, or in a comment, say.