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>From all of your comments, it looks like the issue has to do with the actual text in the file, and not the ability to parse it.  It looks like everyone's solution in here is on the right track, you just need to force the encoding.</p>

<p>The error you are describing is described <a href="http://stackoverflow.com/questions/9233027/unicodedecodeerror-charmap-codec-cant-decode-byte-x-in-position-y-character">in this other StackOverflow post</a>.</p>

<pre><code>with open('contacts_index1.txt', 'r') as f:
     lines = f.read().encode("utf-8").replace("|", "\n")
</code></pre>

<p>EDIT: The issue appears to be a nasty character that wasn't properly decoding. With <code>open</code> you can tell it to ignore characters it can't decode.</p>

<pre><code>import io 
with io.open("contacts_index1.txt", errors="ignore") as f:
    lines = f.read()replace("|", "\n")
</code></pre>

python text split lines