[Tutor] Databases in Python
christopher.henk at allisontransmission.com
christopher.henk at allisontransmission.com
Tue Aug 24 20:24:22 CEST 2010
aug dawg <augdawg09 at gmail.com> wrote on 08/24/2010 01:55:14 PM:
> Now it says that the variable adder is not defined. Does anyone know
about this?
>
It is best if you send the full error message, it helps pinpoint the
problem.
my copy of your code was:
database = []
datafile = open('/home/~/the-db/data')
for line in datafile:
database.append(line)
while tf2 != True:
command = raw_input("Enter a command. >> ")
while tf != True:
if "add" in command:
adder = raw_input("What to add? >> ")
data_base.append(adder)
if "no more" in adder:
tf = True
if "read" in command:
print(database)
if "search" in command:
searcher = raw_input("Enter term to search >> ")
if searcher in database:
# Figure this out.
if "exit database" in command:
print "Bye!"
sys.exit()
I am not sure what you typed in as your command or how your source was
formatted (the tabs did not come through to me) so I cannot say for sure.
If "add" was not your command, adder does not get defined.
My guess is that you typed in a different command so you skipped the
assignment but are checking for "no more" in adder, or attempting to
append adder. This would trigger that error. Did you get the "What to
add? >>" message?
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100824/f6f98674/attachment.html>
More information about the Tutor
mailing list