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
En esta página del sitio puede ver el video en línea #22 - File Handling in Python de Duración hora minuto segunda en buena calidad , que subió el usuario Tech Vitals 31 diciembre 2020, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 209 veces y le gustó 8 a los espectadores. Disfruta viendo!