You don't really have to close it - Python will do it automatically either during garbage collection or at program exit. But as @delnan noted, it's better practice to explicitly close it for various reasons.
So, what you can do to keep it short, simple and explicit:
with open('pagehead.section.htm','r') as f:
output = f.read()
Now it's just two lines and pretty readable, I think.

本文讨论了在Python中使用with语句进行文件读取的最佳实践,这种方法不仅简洁而且能确保文件被正确关闭,适用于各种Python实现。

1748







withstatement the file resource will be closed properly for you. – David Alber Nov 4 '11 at 15:46withstatement makes sure the file is closed "correctly", it's even better than an explicitclose. And it should be available in GAE's Python 2.5. See effbot.org/zone/python-with-statement.htm – Mark Ransom Nov 4 '11 at 15:48output = f.read()part on the same line after the:. – Karl Knechtel Nov 4 '11 at 16:03