View Single Post
Old 02-06-2012, 11:42 AM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,471
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
There are lots of ways to do this ranging from changing the regexp to return more groups to reconstructing the string.

One way:
Code:
	if mg is None:
		return no_page_read_str
	date = mg.group(1)
	date = "{1}/{0}/{2}".format(*date.split('/'))
	pct = mg.group(2)
EDIT: The *date stuff unpacks the list (array) into positional parameters as required by the "format" method. It is explained in the python docs here.

Another way, less magic:
Code:
	if mg is None:
		return no_page_read_str
	date = mg.group(1)
	parts = date,split('/')
	date = parts[1] + '/' + parts[0] + '/' + parts[2]
	pct = mg.group(2)

Last edited by chaley; 02-06-2012 at 11:54 AM. Reason: Hit the post button by mistake
chaley is offline   Reply With Quote