2
I’m trying to make a hangman game, and for that, I’m taking word lists and putting them in files in format .txt for Python to use in the game.
When picking up a list of names of people, have some that comes with parentheses after the name, and among these, more some with equal sign between the parentheses, for example:
Ana Beatriz ( = )
This is due to the site where I copied the names. He had some indications, and could not copy without them come together.
So I created a code for Python to remove these unwanted characters for me:
entrada = open('Pessoas2.txt', 'r') # Cópia da lista de nomes que tenho
saida = open('Pessoas3.txt', 'w') # Local onde as linhas editadas serão escritas
for linha in entrada:
l = entrada.readline()
l = l.replace('(', '').replace(')', '').replace('=', '')
l = l.rstrip()
saida.write(l)
entrada.close()
saida.close()
It was apparently all right, the code works. Only it takes away more things than I want. My original list has 200 names, and the new file contains only 100 names, that is, it simply erases names, and I don’t know why. Could you help me?
Thank you very much. I only made a modification because he wasn’t breaking lines into names that didn’t have those characters that I wanted to remove. So instead of replacing the
')'
for\n
, I left as was and added asaida.write('\n')
at the end of the loop.– Jefferson Carvalho