Okay, continuing on with my little System access project I've been working on. Now I've gotten three different Python files in this Project. I'm using a main menu .py to offer option for the user to select from. Each option then opens one of the other two .py files and runs them respectively. Now, each of these files i've created run fine on their own. But when I launch one of the files from within another, I seen to be getting alot of "Global name 'Whatever' is not defined, and terminates the program. Perhaps all the functions aren't getting loaded properly? I'm really not sure here. I'm going to post each file here, and hope one or more of you may be able to shine some light on this problem for me.
#Main menu Program
import cPickle as p
import sys
def MainMenu():
print 'Main System Menu:'
print 'Please select an option from the following:'
print '1. Create new account.'
print '2. Delete accounts.'
print '3. End Program.'
Choice = raw_input('Enter Selection: ')
if Choice == '1':
my_file = 'UserAccess.py'
execfile(my_file)
elif Choice == '2':
my_file = 'UserDeleteAccess.py'
execfile(my_file)
elif Choice == '3':
print 'Exiting Program, Have a nice day!'
sys.exit()
else:
print 'Invalid selection'
MainMenu()
Variable = MainMenu()
#User Access
import cPickle as p
import sys
def EP(self, temp):
if self.lower() == 'exit':
print 'Returning to Main Menu.'
my_file = 'SystemMenu.py'
execfile(my_file)
if self.lower() in temp:
print 'That username already exists.'
NewAccount()
def NewAccount():
my_file = 'systemaccess.txt'
file_handle = open(my_file, 'r')
temp = p.load(file_handle)
file_handle.close()
print 'Welcome to the System Account Setup.'
print 'Enter Exit to return to Main Menu at anytime.'
Username = raw_input('Please enter the username you desire: ')
EP(Username.lower(), temp)
Password = raw_input('Enter your desired password: ')
EP(Password.lower(), temp)
temp[Username.lower()] = Password.lower()
file_handle = open( my_file, 'w' )
p.dump(temp, file_handle)
file_handle.close()
print 'New account created.'
CreateAccount()
def CreateAccount():
repeat = 'Y'
while repeat == 'Y':
repeat = raw_input('Would you like to create another account?(Y/N):').upper()
if repeat == 'Y':
NewAccount()
elif repeat == 'N':
print 'Thank you for using the System Account Setup. Returning to Main Menu'
my_file = 'SystemMenu.py'
execfile(my_file)
else:
CreateAccount()
Variable = NewAccount()
#Delete access
import cPickle as p
import sys
def LoadAdmin():
my_file = 'adminaccess.txt'
file_handle = open(my_file, 'r')
Adminfile = p.load(file_handle)
file_handle.close()
DeleteAll(Adminfile, my_file)
def LoadAccounts():
my_file = 'systemaccess.txt'
file_handle = open(my_file, 'r')
Accountlist = p.load(file_handle)
file_handle.close()
Menu(Accountlist, my_file)
def Menu(Accountlist, my_file):
print ''
print 'Welcome to the Account Deletion Menu.'
print 'Please choose from the following options.'
print '*********************'
print '1. Delete single account.'
print '2. Delete all accounts.(Requires Administrator Access)'
print '3. Exit to Menu.'
print '*********************'
Choice = raw_input('Enter Selection:')
if Choice == '1':
DeleteSingle(Accountlist, my_file)
elif Choice == '2':
LoadAdmin()
elif Choice == '3':
ExitToMenu()
else:
print 'Invalid Choice Selection.'
Menu(Accountlist, my_file)
def DeleteSingle(Accountlist, my_file):
print 'Please enter the account you wish to delete,'
AccountDel = raw_input('Enter exit to return to the Account Deletion Menu: ').lower()
if AccountDel.lower() == 'exit':
Menu(Accountlist, my_file)
elif AccountDel in Accountlist:
AccountPass = raw_input('Please enter the pasword for this acount: ').lower()
elif AccountDel not in Accountlist:
print 'That account does not exist.'
print
DeleteSingle(Accountlist, my_file)
if AccountPass == Accountlist[AccountDel]:
del Accountlist[AccountDel]
file_handle = open(my_file, 'w')
p.dump(Accountlist, file_handle)
file_handle.close()
print 'Account has been Deleted.'
LoadAccounts()
else:
print 'Invalid Password'
print
DeleteSingle(Accountlist, my_file)
def DeleteAll(Adminfile, my_file):
Access = raw_input('Please enter administrator access code: ').lower()
if Access == Adminfile['administrator']:
my_file = 'systemaccess.txt'
file_handle = open(my_file, 'r')
Accountlist = p.load(file_handle)
file_handle.close()
Accountlist.clear()
file_handle = open(my_file, 'w')
p.dump(Accountlist, file_handle)
file_handle.close()
print 'All Accounts have been deleted.'
print
LoadAccounts()
else:
print 'Administrator Password incorrect.'
print
DeleteAll(Adminfile, my_file)
def ExitToMenu():
my_file = 'SystemMenu.py'
execfile(my_file)
Variable = LoadAccounts()
I hope someone can lead me down the right path here. And I'm so sorry for having posted multiple times here today. I've been at this for the better part of the day, and I'm quite happy with the progress I've made. I'm having alot of fun learning this stuff!!
Thanks in advance folks, you're all just great in my book.