I'm a beginner, free time training about two months ago and so far my programs had 5 lines, very simple. This program taught me a lot of new concepts, and it's part of a larger program that I plan to do.
def dicionario(palavra):
f = open("portugues.txt", "r")
for line in f:
if palavra in line:
f.close()
return "Existe"
f.close()
return "Nao existe"
if __name__ == "__main__":
palavra = input('Digite a palavra a procurar: ')
dicionario(palavra)
input()
When I use IDLE, I open the file as f, and the for block works, returning "Exist" as long as the word is in the dictionary. When I execute the whole program, by Pycharm or Python itself, the program asks for the word to fetch and then it stops, without error message. NOTE: The dictionary (portugues.txt) is in PYTHONPATH, in the same directory as the program. I use Windows 8. What is missing? I would like to use this function in another program via import, can you do it like this?