Ask Question
9 December, 00:02

Write a code segment that prompts the user for a filename. If the file exists, the program should print its contents on the terminal. Otherwise, it should print an error message.

+5
Answers (1)
  1. 9 December, 03:59
    0
    Code is written in Python

    dataobject = DataTransferinFiles ()

    Should be just:

    dataobject = DataTransferinFiles ()

    So the full code:

    class DataTransferinFiles ():

    def transfer (self, firstfilename, secondfilename):

    print ("your first file is=", firstfilename);

    print ("your second file is = ", secondfilename)

    with open (firstfilename,'r') as filedа ta:

    firstfiledata = filedata. readlines ()

    print ()

    print ("1st file reading complete")

    print ()

    with open (secondfilename, 'r') as filedа ta:

    secondfiledata=filedata. readlines ()

    print ("2st file reading complete")

    for eachline in firstfiledа ta:

    filesecond = open (secondfilename,'a')

    filesecond. write ("/n"+eachline + "/n")

    print ("1st file transfered in to second file")

    for eachline in secondfiledа ta:

    filefirst = open (firstfilename)

    filefirst. write ("/n"+eachline + "/n")

    print ("second file transfered in to first file")

    dataobject = DataTransferinFiles ()

    firstfilename = input ("enter first file name for transfer")

    secondfilename = input ("enter second file name for transfer")

    dataobject. transfer (firstfilename, secondfilename)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a code segment that prompts the user for a filename. If the file exists, the program should print its contents on the terminal. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers