2 ms·
Some languages (Python, Ruby, probably dozens of others) have constructs along these lines with f = open("data.txt") print f.readline() The file is auto
by pmontra 7y ago
Some languages (Python, Ruby, probably dozens of others) have constructs along these lines
with f = open("data.txt")
print f.readline()
The file is automatically closed at the end of the block. Those languages also have explicit open/close/seek calls to let the developer implement more complex cases.
Btw, the os closes any open file when the program ends.
- ErotemeObelus 7y agoYes, you're correct that os's have some kind of rudimentary reference counting for files, but it's very inchoate and not designed as the primary method of handling file references.