count lines and create new file
<p>So basically I have to call the text file, and create the new file while adding some strings.</p>

<p>For example if my input text is:</p>

<p>Hello</p>

<p>World</p>

<p>Nice to Meet You</p>

<p>my output text has to be:</p>

<p>1: Hello</p>

<p>2: World</p>

<p>3: Nice to Meet You</p>

<p>Below is the code that I have been trying to figure out. When I try it, there is no error, but it does not create the new file too. </p>

<pre><code>with open('filetext') as f:
    content=f.readlines()   
    for count in f:
        count+=1
        with open('newfiletext', 'a+') as f:     
        f.write(counts)
        f.write(': ')
        f.write(content)
        f.write('\n')
</code></pre>

<p>I appreciate if I can get a help. Thank you in advance.</p>

<p>textfile:</p>

<pre><code>Hello
World
Nice to Meet You
</code></pre>

<p>code:</p>

<pre><code>with open('test.txt') as f:
    for i , line in enumerate(f.readlines()):
        print "{0}:{1}".format(i+1,line)
</code></pre>

<p>output:</p>

<pre><code>1:Hello

2:World

3:Nice to Meet You
</code></pre>

<p>then you can store in string and write the to file or another file</p>

python