#22 - File Handling in Python

Publicado em: 31 Dezembro 2020
no canal de: 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  


Nesta página do site você pode assistir ao vídeo on-line #22 - File Handling in Python duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Tech Vitals 31 Dezembro 2020, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 209 vezes e gostou 8 espectadores. Boa visualização!