File Object (फाइल ऑब्जेक्ट) :-
File object Python में वह object है, जिसके माध्यम से किसी open file को access किया जाता है। इसका उपयोग file से data पढ़ने, data लिखने, file position जानने और file बंद करने के लिए किया जाता है।
English-
A file object is an object returned by open() that provides methods and attributes for interacting with an opened file.
Example-
file = open("demo.txt", "w", encoding="utf-8")
file.write("Hello")
print(file.closed)
file.close()
print(file.closed)
Output:
False
True
Explanation -
open() से file object file में store होता है।
file.write("Hello") file में text लिखता है।
file.closed बताता है कि file बंद है या नहीं।
File open होने पर file.closed का मान False होता है।
File बंद होने के बाद इसका मान True होता है।