[Type C]Q7. Write a Program that appends the contents of one file to another. Have the program take the filenames from the user.

What is file handling?

Python has several functions for creating, reading, updating, and deleting files.

The key function for working with files in Python is the open() function.

The open() function takes two parameters; filename, and mode.

There are four different methods (modes) for opening a file:

"r" – Read – Default value. Opens a file for reading, error if the file does not exist

"a" – Append – Opens a file for appending, creates the file if it does not exist

"w" – Write – Opens a file for writing, creates the file if it does not exist

"x" – Create – Creates the specified file, returns an error if the file exists

The close() command terminates all the resources in use and frees the system of this particular program.

Program code:


Enter file to be read from:Athletics_data.txt
Enter file to be appended to:Poem.txt

File Handling in python is demonstrated in above program.

To view all the lessons in chapter 1: http://computertutor.in/class-12-computer-science/chapter-5/

To view entire class 12 computer science study material: http://computertutor.in/resources/

You cannot copy content of this page