According to the Python 2.7 manual this construction of the with statement should work:
text = "aim low and reach it"
fname = "test7.txt"
with open(fname, 'w') as foutp, open(fname, 'r') as finp:
# write text to file
foutp.write(text)
# read text from file
mytext = finp.read()
print("to file --> %s" % text)
print('-'*30)
print("from file --> %s" % mytext)
""" my result -->
to file --> aim low and reach it
------------------------------
from file -->
"""
It writes the file out, but does not read it in. There is no error traceback.