/
๐Ÿ

use "with" syntax in python

python

Every object that has entrie() or exit() method can used with "with" syntax.

Use open() with "with" and after the "with" block file automatically close.

python
with open("test.py") as Pyfile, open("target.txt") as target:
print("Files opened")
print("Files Closed")
Edit this page
logo
Hi Mohsen save your notes