#22 - File Handling in Python

Published: 31 December 2020
on channel: Tech Vitals
209
8

Learn about File Handling in Python. We can open files, read the contents of the file, write the contents into the file and also add some new contents in the file using the file handling in Python. We use open function for the file handling which takes two parameters. The first parameter is the file name and the second parameter is the mode to determine why do we want to open that file. We use 'r' for read mode, 'w' for write mode and 'a' for append mode.

When we open a file, we should always close that file after our program is completed. If we don't close the file, that file will be stored on the memory even if the program has been completed. When we are working on the project, most of the time we forget to close the file. To avoid that, we can use Context Manager in Python. Context manager allows us to allocate and release the resources like files or database with a code block in between. The most common example of context manager is with statement. Using the context manager, we write all the file handing code within a block and when that block is completed, python will automatically close the file for us.

Facebook:   / techvitals  


On this page of the site you can watch the video online #22 - File Handling in Python with a duration of hours minute second in good quality, which was uploaded by the user Tech Vitals 31 December 2020, share the link with friends and acquaintances, this video has already been watched 209 times on youtube and it was liked by 8 viewers. Enjoy your viewing!