Question: IN PYTHON, modify the function copy_file by doing the following: Download the Project Gutenberg version of The Adventures of Sherlock Holmes from http://www.gutenberg.org/cache/epub/1661/pg1661.txt (Links to
IN PYTHON, modify the function copy_file by doing the following:
Download the Project Gutenberg version of The Adventures of Sherlock Holmes from http://www.gutenberg.org/cache/epub/1661/pg1661.txt (Links to an external site.)Links to an external site. (Project Gutenberg is a wonderful resource for non-copyright-protected texts.) Call your file-copying function to make a copy of this file. [Some problems have been reported with reading Project Gutenberg files. If you run into messages saying that Python can't decode a character, open the file with open(infile_name, 'r', errors='ignore').]
(e.2) Modify your copy_file function to take one parameter, a string. If the parameter is 'line numbers', the copied file includes line numbers at the start of each line :
1: Project Gutenberg's The Adventures of Sherlock Holmes, by Arthur Conan Doyle 2: 3: This eBook is for the use of anyone anywhere at no cost and with ... 13052: subscribe to our email newsletter to hear about new eBooks.
If the parameter is anything else, the function just copies the file as before.
Note that the line number is formatted and right-justified in a five-character field. You did this task last week, so you should be able to reuse most of last week's solution.
this is my copy_file function: def copy_file(): infile_name = input("Please enter the name of the file to copy: ") infile = open(infile_name, 'r', encoding='utf8') outfile_name = input("Please enter the name of the new copy: ") outfile = open(outfile_name, 'w', encoding='utf8') for line in infile: outfile.write(line) infile.close() outfile.close()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
