Ask Question
29 September, 16:10

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. 29 September, 17:38
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers