I am trying to create a code library where I can store code snippets I find over time and retrieve them. Here is my code so far.
# Python Code Library User Interface
import sys
class CodeLib:
codes = []
option = ['help (-h)', 'list (-l)', 'import (-i)', 'quit (-q)']
#What does the user want to do?
print "Welcome to the Code Library"
print "What would you like to do? \n %s" % option
choice = raw_input()
print choice
if choice == 'quit' or '-q':
sys.exit()
length = len(choice)
# Getting name of file to import if user chooses import before
# viewing the code list
if choice[0] == 'i':
_file_ = choice[6:length]
elif choice[:2] == '-i':
_file_ = choice[2:length]
# imports file if user chose import before viewing code list
if choice[0:5] == 'import' or choice [0:2] == '-i':
import _file_
# If user chose option other than import at beginning
# then perform option chosen then give ability to do something else
while choice != 'quit' or '-q':
# provides basic help menu
if choice == 'help' or '-h':
print
print '''(list or -l) brings up a list of code snippet names
(import or -i)/file_name brings up the code snippet you chose \n'''
# provides list of code files
elif choice == 'list' or '-l':
print codes
print option[2], "file name"
_file2_ = raw_input()
import _file2_
# imports code file
else:
_file2_ = raw_input()
import _file2_
# Next user option
print "What would you like to do?"
choice = raw_input
Now I know this is very incomplete so far. But the issue I am running into is that no matter what I enter as choice. The program does the first if statement, which exits the program. I have commented out the first if statement and tried again. But then no matter what I enter as choice. It performs this first if statement in the while loop and I just get stuck in a loop. So I'm not sure what is wrong but can someone help me out here?