To input the input-file and output-file names, simply use the input(s)
function where s
is the input message.
To get the "content inside the input file provided by the user to print into the output file," that would mean reading the input file and writing the read data into the output file.
To read the input file, use f = open(input_filename, 'r')
, where the first argument is the filename and the second argument is the open mode where 'r'
means read. Then letting readtext
be the read text information of the input file, use readtext = f.read()
: this returns the entire text content of f
.
To output the read content to the output file, use g = open(output_filename, 'w')
, noting that now the second argument is 'w'
, meaning write. To write the data, use g.write(readtext)
.
Please note that an exception will be raised if the input file is not found or the output file is invalid or not possible as of now. To handle these exceptions, use a try-except block.
This is effectively a file-copying operation in Python. shutil
can serve as a useful alternative.