Hi everybody,
Can you please help me to fix this error:
For exit press 'q'
Please enter name :Jack London
For exit press 'q'
Please enter name :C.S. Lewis
For exit press 'q'
Please enter name :q
Traceback (most recent call last):
File "/home/serg/python/First/start/Q1.py", line 28, in <module>
print row[0], row[1]
TypeError: 'NoneType' object is not subscriptable
And this is the code:
import MySQLdb as mdb
import sys
con = mdb.connect('localhost',
'root',
'',
'cartapp')
with con:
cur = con.cursor()
cur.execute('DROP TABLE IF EXISTS Writers')
cur.execute("""
CREATE TABLE Writers
(
Id INT PRIMARY KEY AUTO_INCREMENT,
Names VARCHAR(25)
)
""")
while True:
print "For exit press 'q'"
name = raw_input("Please enter name :")
if name == 'q': break
cur.execute('INSERT INTO Writers(Names) VALUES("%s")' % name)
numrows = int(cur.rowcount)
for i in range(numrows):
row = cur.fetchone()
print row[0], row[1]