ChefNinja
10-18-2002, 06:53 AM
OK, this actually started out as a joke with a friend of mine. We were talking about taking paintball guns out on Halloween night and stirring up a little trouble. Anyways, as we were talking, I kept joking with him about how he just made my hitlist and such...
So then I decided I should write a hitlist keeper tracker thing! :D
Anyway.. its pretty sloppy.. but that doesn't matter cuz its not really meant for anything :P
class Hitlist:
def __init__(self):
try:
self.names = []
self.list = []
for line in open("hitlist.txt", "r").readlines():
self.names.append(line)
for item in self.names:
str = item
str2 = str[:-1]
self.list.append(str2)
except:
self.nlist = []
def add(self, name):
try:
if name in self.list:
print "Name already on hitlist:", name + "\n"
else:
self.list.append(name)
file=open("hitlist.txt", "w")
for item in self.list:
file.write(item+"\n")
file.close()
print "Added to hitlist:", name + "\n"
except:
print "Could not add to list"
def remove(self, name):
try:
if name in self.list:
self.list.remove(name)
file=open("hitlist.txt", "w")
for item in self.list:
file.write(item+"\n")
file.close()
print "Removed from hitlist:"+"\n", name
else:
print "Was not found on hitlist:"+"\n", name
except:
print "Could not remove from list:", name
def display(self):
try:
if len(self.list) > 0:
print "Current hitlist:\n"
for item in self.list:
print item
print "\n"
else:
print "No hitlist found\n"
except:
print "No hitlist found\n"
def printmenu():
print "-----------------------------"
print "1. Add person to hitlist"
print "2. Remove person from hitlist"
print "3. View hitlist"
print "9. Quit"
def add_person():
name = raw_input("\nName to add: ")
x = Hitlist()
x.add(name)
main()
def rem_person():
name = raw_input("\nName to remove: ")
x = Hitlist()
x.remove(name)
main()
def display_list():
print "\n"
x = Hitlist()
x.display()
main()
def main():
dict = {'1':'add_person()', '2':'rem_person()',
'3':'display_list()', '9':'sys.exit()'}
try:
printmenu()
choice = raw_input("Enter choice: ")
exec dict[choice]
except KeyError:
print "Must enter a valid choice.\n"
main()
if __name__ == '__main__':
main()
Enjoy making your new hitlist ;)
So then I decided I should write a hitlist keeper tracker thing! :D
Anyway.. its pretty sloppy.. but that doesn't matter cuz its not really meant for anything :P
class Hitlist:
def __init__(self):
try:
self.names = []
self.list = []
for line in open("hitlist.txt", "r").readlines():
self.names.append(line)
for item in self.names:
str = item
str2 = str[:-1]
self.list.append(str2)
except:
self.nlist = []
def add(self, name):
try:
if name in self.list:
print "Name already on hitlist:", name + "\n"
else:
self.list.append(name)
file=open("hitlist.txt", "w")
for item in self.list:
file.write(item+"\n")
file.close()
print "Added to hitlist:", name + "\n"
except:
print "Could not add to list"
def remove(self, name):
try:
if name in self.list:
self.list.remove(name)
file=open("hitlist.txt", "w")
for item in self.list:
file.write(item+"\n")
file.close()
print "Removed from hitlist:"+"\n", name
else:
print "Was not found on hitlist:"+"\n", name
except:
print "Could not remove from list:", name
def display(self):
try:
if len(self.list) > 0:
print "Current hitlist:\n"
for item in self.list:
print item
print "\n"
else:
print "No hitlist found\n"
except:
print "No hitlist found\n"
def printmenu():
print "-----------------------------"
print "1. Add person to hitlist"
print "2. Remove person from hitlist"
print "3. View hitlist"
print "9. Quit"
def add_person():
name = raw_input("\nName to add: ")
x = Hitlist()
x.add(name)
main()
def rem_person():
name = raw_input("\nName to remove: ")
x = Hitlist()
x.remove(name)
main()
def display_list():
print "\n"
x = Hitlist()
x.display()
main()
def main():
dict = {'1':'add_person()', '2':'rem_person()',
'3':'display_list()', '9':'sys.exit()'}
try:
printmenu()
choice = raw_input("Enter choice: ")
exec dict[choice]
except KeyError:
print "Must enter a valid choice.\n"
main()
if __name__ == '__main__':
main()
Enjoy making your new hitlist ;)