To read contents of a file:
data = open(filename, \"r\").read()
The open file immediately stops being referenced anywhere, so the file obje
Even though it works as expected, I think it fails in two counts:
import this
in the Python prompt to retrieve it) "explicit is better than implicit" and, by failing to explicitly close the file, you could confuse someone who, down the road, will be left with your code for maintenance.It really helps being explicit! Python encourages explicit style.
Other than that, for a throwaway script, your style makes sense.
Maybe you will benefit from this answer.