Hey I am very new to python but I am trying to make a simple registration system. I would like to be able to have a function update when I add a member but I cannot figure out how. As you will see in the code below, once I am finished adding a member in menu option 2, when I go back and try menu option 1 the member I have just added does not show up. How do I make the show_members function reload the updated dictionary?
In addition to my above question, any advice on ways to improve the below code would be welcome. And yes I know that it is very incomplete but it is a WIP.
import sys
import shutil
import os
tmp = os.path.isfile("members.py.tmp")
if tmp == True:
os.remove("members.py.tmp")
shutil.copyfile("members.py", "members.py.tmp")
from members import members
def show_menu():
os.system("clear")
print "\n","*" * 12, "MENU", "*" * 12
print "1. List members"
print "2. Add member"
print "3. Delete member"
print "99. Save"
print "0. Abort"
print "*" * 28, "\n"
return input("Please make a selection: ")
def show_members(members):
for keys in members.keys():
os.system("clear")
print "\nNames", " ", "Code"
print keys, " - ", members[keys]
def add_member(members):
os.system("clear")
name = raw_input("Please enter name: ")
code = raw_input("Please enter code: ")
members[name] = code
return members
#with open("foo.txt", "a") as f:
# f.write("new line\n")
running = 1
while running:
selection = show_menu()
if selection == 1:
show_members(members)
print "\n> " ,raw_input("Press enter to continue")
elif selection == 2:
add_member(members)
print "\n> " ,raw_input("Press enter to continue")
elif selection == 99:
shutil.copyfile("members.py.tmp", "members.py")
elif selection == 0:
os.remove("members.py.tmp")
sys.exit("Program Aborted")
else:
os.system("clear")
print "That is not a valid option!"
print "\n> " ,raw_input("Press enter to continue")