Let's say we want to implement an equivalent of the PHP's file_get_content
.
What is the best practice? (elegant and reliable)
Here are some proposition, are they correct?
using "with" statement:
def file_get_contents(filename):
with file(filename) as f:
s = f.read()
return s
using is using standard open safe?
def file_get_contents(filename):
return open(filename).read()
What happens to file descriptor in either solution?