I've written a program to check for and add words to a txt file stored locally in my working directory, but this file is not affected either during or after my program runs. This program is obviously not secure as far as user input, but is for personal use so I am not worrying about that. The code is as follows:
import os
currentPath = os.getcwd()
writePath = "C:PretendThisIsADirectory\\Documents\\Folder\\file.txt"
def addWord(word):
exists = findWord(word)
words = word.split()
for i in range(len(exists)):
if(exists[i]):
words.remove(exists[i])
print(exists[i])
if word == "Z":
exit
with open(writePath, mode='a') as dst:
dst.writelines(words)
def findWord(word):
if word == "Z":
exit
words = word.split()
with open(writePath,mode="r") as src:
fullStr = src.read()
for line in fullStr:
if line == word:
words[line] = True
return words
print("Input word to add or Z to skip:")
word = input()
addWord(str(word))
print("Input word to find or Z to skip:")
word = input()
findWord(str(word))
I have tried narrowing down the directory and at this point am just using the direct file path from C:. I have checked the file continuously throughout numerous iterations of the program, but it has never been updated.