0

Hello!
I am trying to write a function that looks for a desired string pattern within a table (Countries). Look at the code.

def selectCountry():
	print 'Enter country:'
	country = raw_input('> ')
	sql = '''select idCountries,CountryEn from Countries where CountryEn REGEXP '%s''''
	cursor.execute(sql,(country))
	result = cursor.fetchall()
	rowHead = 'Country ID','Country name'
	result = listit(result)
	rowHead = list(rowHead)
	result.insert(0,rowHead)
	table = texttable.Texttable()
	table.set_cols_align(["c","c"])
	table.set_cols_valign(["m","m"])
	table.set_cols_width([10,20])
	table.add_rows(result)
	print table.draw()

When I run this it returns an error.

sql = '''select idCountries,CountryEn from Countries where CountryEn REGEXP '%s''''
SyntaxError: EOL while scanning string literal

How can I program it so that it search for any desired pattern? I know how to do it for a single pattern directly in MySQL.
Cheers!

Dani

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by acrocephalus
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.