Python : split text to list of lines
<p>am new to Python , But i have text File like :</p>

<pre><code>12345 | 6789 | abcd | efgh 
</code></pre>

<p>i want my output be Like :</p>

<pre><code>12345
6789
abcd
efgh
</code></pre>

<p>=====================</p>

<p>i really don't know the script 
but i made a lot of scripts  by those function split() , strip() , blame blame blame </p>

<p>but i failed to do it 
so am asking for help is someone can .</p>

<p>i will appreciate any Help .</p>

<pre><code>with open('contacts_index1.txt') as f:
    lines = f.read().splitlines("|")
</code></pre>

<p>Some problems with the code you posted:</p>

<ul>
<li><code>f.read</code> doesn't read the whole line. It should be <code>f.readline()</code>. </li>
<li>What is the function <code>splitlines</code>?</li>
</ul>

<p>Your question is pretty unclear in differnt aspects. Maybe this snippet could be of some help:</p>

<pre><code>for line in open('contacts_index1.txt'):
    elements = line.split('|')
    for element in elements:
        print element.strip()
</code></pre>

<p>Editted: I didn't know the function <code>splitlines</code>. Just looked it up. The way you used it in your code doesn't seem to be correct anyway.</p>

python text split lines