#22 - File Handling in Python

Pubblicato il: 31 dicembre 2020
sul canale di: 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  


In questa pagina del sito puoi guardare il video online #22 - File Handling in Python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Tech Vitals 31 dicembre 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 209 volte e gli è piaciuto 8 spettatori. Buona visione!