[Python] Why can't i call the function?
Go to solution
Solved by Neil,
Best practice for this sort of stuff would look something like this:
https://gist.github.com/NeilHanlon/aecca949a4fa764127bd
Essentially what I did was abstract your "main selection" code so it's only in one place. You had a lot of printing the same thing over and over, which isn't good code.
Next, I added the following to the bottom:
if __name__ == '__main__': #__name__ is a superglobal that is set to __main__ if the file is called by execution of the actual file (not by importing, etc), so this will only run if you do "python file.py" or run it from an IDE. """Create Dictionary "options" with a relational mapping between the user input (integer) and a function name. Therefore we can call options[1]() to have it run login_Driver(), etc.""" options = { 1: login_Driver, 2: login_Customer, 3: create_Account, } opt = main_Selection() #main_Selection method now returns the user's input. while opt is not 4: # while the user hasn't entered a 4 (exit), continue into this block. options[opt]() #call the function the user is looking for, based on the above dictionary opt = main_Selection() #re-run main_Selection to return the new input from the user.
EDIT: FFs... it cut off the entire end of my response...
I'm not re-typing it. If you need any help or have questions, please let me know. I'm happy to share my knowledge

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now