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

Recommended Answers

All 2 Replies

Use normal double quotes instead of triple single quotes for multiple lines.

Thank you so much! Solved!!
Dani

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.