Python 3 programming Tutorial: With Statement (opening a file)

Pubblicato il: 09 gennaio 2016
sul canale di: WhatDidILearnToday
32,160
399

python 3 programming Tutorial - How to: the with - as statement

Python's with statement explained and demonstrated.

Example on using the "with" - statement, when opening a file on the hard drive.

The tutorial shows how to open a file on your computer using the open() function in Python. First the most standard way is demonstrated by using the open() function on its own. When, the Python's 'with - statement is used in comparison with the open() function. Through this, it can be seen how the 'with' - statement simplifies working with particular objects. These objects need to provide two methods.

1. __enter__() method
2. __exit__() method

The 'with' - statement call both methods implicitly at different times. This is demonstrated in this video by creating a custom object which does define both of these methods. I can be seen when the 'with' - statement calls these methods and how their implementation can be used.


In questa pagina del sito puoi guardare il video online Python 3 programming Tutorial: With Statement (opening a file) della durata di ore minuti seconda in buona qualità , che l'utente ha caricato WhatDidILearnToday 09 gennaio 2016, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 32,160 volte e gli è piaciuto 399 spettatori. Buona visione!