I am trying to import function from one code to another, first program is executing .txt file and searching if word exists:
exists = 0 #To import this variable to other code i have to this
path = 'D:\Python\database.txt'
def search(search_word):
file = open(path)
strings = file.read()
if(search_word in strings):
exists = 1
else:
exists = 0
Other code:
word = input("Enter one word: ")
search(word)
if exists == 1:
print("This word exists in database!")
else:
print("This word doesn't exist in database!")
Even if word is in databse program prints "This word doesn't exist in database!". Problem is that I can't update local variable exists in function search. I tried to use global exists, it doesn't work! Please help!