I am trying to write a function that reads keywords from a file (in the format that each keyword is on a new line inside the text file)
I want the function to put the keywords into a global set() called "desiredItems".
desiredItems = set()
def populateDesired():
for line in open("desireditems.txt"):
addableLine = line.rstrip("\n")
global desiredItems.add(addableLine)
For some reason my development environment (Pycharm) tells me that desiredItems.add is invalid syntax.
(sorry If I have inserted code snippet incorrectly etc)
Thanks in advance
You don't need to use
global
at all, just remove it.