First I extracted a list of colleges from a college website in the form of tuple of tuples:
(('name1', 'address1'), ('name2', 'address2'), ('name3', 'address3'))
then I want to write this is in a database named 'sample' and in table 'collegelist'. Table has two fields (name varchar(400) not null, address varchar(500)):
Here is the code:
for college in tuples:
cursor.execute('INSERT INTO collegelist (name, address) VALUES ("%s", "%s")') %(college[0], college[1])
db.commit()
db.close()
But it always give following TypeError:
TypeError: unsupported operand type(s) for %: 'long' and 'tuple'
I also tried inserting only names and leaving addresses then I get following type Error:
TypeError: unsupported operand type(s) for %: 'long' and 'str'
Now i don't understand from where 'long' type came. There are only strings and tuples in the program.
Note: Names and addresses of colleges have single quotes, double quotes, dash, period.
Why is this error coming and how can I remove it? Thanks in advance.