Ask Question
28 January, 20:42

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.

+4
Answers (1)
  1. 28 January, 20:55
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers