I am experimenting with calling functions using dictionary keys. At the moment there is only one function in the dictionary but I plan to add more. The code below works to display the list because the function 'loadlist' has no arguments and I have written 'gameone.txt' into the body code when opening the file as f.
I want to have the file name as an argument of the loadlist function so that the user types for example... loadlist('gameone.txt') or loadlist('gametwo.txt') etc depending on what they want to have displayed.
def interact():
command = raw_input('Command:')
def loadlist():
with open('gameone.txt', 'r') as f:
for line in f:
print line
dict = {'loadlist': loadlist}
dict.get(command)()
return interact()
interact()
I have tried the code below but I cannot solve my problem.
def interact():
command = raw_input('Command:')
def loadlist(list):
with open(list, 'r') as f:
for line in f:
print line
dict = {'loadlist': loadlist}
dict.get(command)()
return interact()
interact()
Thanks for any input.