how to delete all lines after a certain string in a file and then add some more lines using python : <p>I want to delete all the lines in a file smart.txt and then add some strings of my own. smart.txt contains alot of lines.</p>

<p>I tried</p>

<pre><code>import sys
import os

output=[]
f= open(smart.txt, 'r')
for line in f:
 output.append(line)
 if '*** P R O P E R T I E S ***' in line: break
f=open(smart.txt, 'w')
[f.write(data) for data in output]
f.write('*** Inclusions ***\n ')
f.write('*** Permanent  ***\n ')
f.close()
</code></pre>

<p>I am getting an error</p>

<pre><code>f= open(smart.txt, 'r')
NameError: name 'smart' is not defined
</code></pre>

<p>cannot figure out because smart.txt is present in the same directory.</p>

<p>Any suggestions?</p>
