parsing a text file with python

0

I am new to the platform and to the world of python.

I would like to be able to make a small script in which I give a file.txt, which contains a text string separated by | , and for each | that there is a line break (I understand it would be a \ n), but I can not find the correct way to do it. I do not know if it would be with a for, and in case of being so I sentence use to tell you that for every | find a line break.

by way of example:

input: 

textouno|textodos|textotres
output:

textouno
textodos
textotres

Enclosed code that I have so far:

from io import open
path = 'C:/Users/mark/Desktop/pipelines.txt'
archivo = open(path,'r')

# (aqui entiendo que deberia venir la parte del parseo)

print (archivo.read())
archivo.close()

Thank you very much

    
asked by m477 19.11.2018 в 19:13
source

1 answer

0

To replace characters in a string use replace.

Ex:

a = 'linea uno|linea dos|linea tres|'
b = a.replace('|','\n')
    
answered by 28.12.2018 в 04:11