With Statement:-
Python में file को open करते समय, with statement का प्रयोग किया जाता है जब किसी file को with statement के साथ open किया जाता है तो उसे close करने की आवश्यकता नहीं होती है file automatically close हो जाती है।
Syntax:-
with open(“file_name.extension_name”, “mode”) as fp:
How to check file is closed or not
print(fp.closed)
with open(“ii.txt”,’w’) as fp: a=”akhilesh” fp.write(a) print(fp.closed) print(fp.closed) |
With Statement:-
While opening a file in Python, with statement is used. When a file is opened with with statement then there is no need to close it, the file gets closed automatically.
Syntax:-
with open(“file_name.extension_name”, “mode”) as fp:
How to check file is closed or not
print(fp.closed)
with open(“ii.txt”,’w’) as fp: a=”akhilesh” fp.write(a) print(fp.closed) print(fp.closed) |