Formatting a column's value output

Ferrous Cranus nikos.gr33k at gmail.com
Sun Jan 27 10:04:25 CET 2013


Τη Κυριακή, 27 Ιανουαρίου 2013 12:26:44 π.μ. UTC+2, ο χρήστης Michael Torrie έγραψε:

> A tuple is one method for passing variables into the string formatter.
> 
> So if you need to display something twice, just put in two "%s" in the
> 
> format string, and pass it the same variable twice.

Yes i know what a tuple is, iam just telling that the next code:
================================
	try:
		cur.execute( '''SELECT URL, hits FROM counters ORDER BY hits DESC''' )
	except MySQLdb.Error, e:
		print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] )
	else:
		data = cur.fetchall()
		
		for row in data:
			print ( "<tr>" )
				
			for item in row:
				print( '''<td>  <a href='http://www.%s?show=log'>%s</a>  </td>''' % (item, item) )
			
		sys.exit(0)
=================================
1. ruteruns a dataset
2. seperate each rows
3. itermate over the items of a row.

Okey, so far BUT i want the url linking to happen only for the URL column's value, and not for the hits column too. How do i apply the url link to the URL column's value only?



More information about the Python-list mailing list