0
I read a file . txt where I want to separate each word by comma, ie when finding a space before the word and after.
But I also need to ignore the entire txt line where the ##character is. Below follows the code I was using to separate in comma:
def LeArquivo(arquivo):
linhas = arquivo.readlines()
texto = []
for line in linhas:
line = line.strip().split(' ')
texto.append(line)
return texto
Here’s the code I was trying to use to remove the ##
def LeArquivo(arquivo):
linhas = arquivo.readlines()
texto = []
for line in linhas:
line = line.strip().split(' ')
if line.find('##') != 0:
texto.append(line)
return texto
But an error occurs when executing: Attributeerror: 'list' Object has no attribute 'find'
The condition could also be
if(not linha.startswith('##')):...
. Good answer/explanation– Miguel
cool! was unaware of the
"##" not in str
– JJoao
Thanks for the help @Giovanni, it worked perfectly here! With your tips I even managed to make other parts of the code I needed. Vlw!
– Heitor Henrique