Sameh Weangy Sameh Weangy - 6 months ago 39
Python Question

Python : split text to list of lines

am new to Python , But i have text File like :

12345 | 6789 | abcd | efgh

i want my output be Like :



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

but i failed to do it
so am asking for help is someone can .

i will appreciate any Help .

with open('contacts_index1.txt') as f:
lines ="|")


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.

The error you are describing is described in this other StackOverflow post.

with open('contacts_index1.txt', 'r') as f:
     lines ="utf-8").replace("|", "\n")