 <pre><code>with open("f1") as f1,open("f2") as f2: if f1.read().strip() in f2.read(): print 'found' </code></pre> <p>Edit: As python 2.6 doesn't support multiple context managers on single line:</p> <pre><code>with open("f1") as f1: with open("f2") as f2: if f1.read().strip() in f2.read(): print 'found' </code></pre>