>>> import re
>>> sss = "SELECT a.id, a.customer_id as user_id, c.image au_icon, c.nick_name au_name, a.title, a.content, a.cover_image image_url, UNIX_TIMESTAMP(ifnull(a.last_update, a.ctime)) last_update, a.goods * 3+ a.goods_init ups, a.views * 3+ a.views_init play_count, a.reviews comment_count, IF(a.is_essence, 'true', 'false') is_essence, a.type, a.game_id, g.title game_name, UNIX_TIMESTAMP(a.ctime) create_time, a.images FROM articles a LEFT JOIN games g ON g.is_del= 0 AND g.id= a.game_id left join customers c on a.customer_id= c.id where a.is_del= 0 and a.status= 1 AND a.type= 'video' AND a.game_id!= 223 and a.id IN(1)"
>>> pattern = re.compile('[ ]+')
>>> re.sub(pattern, ' ', sss)
"SELECT a.id, a.customer_id as user_id, c.image au_icon, c.nick_name au_name, a.title, a.content, a.cover_image image_url, UNIX_TIMESTAMP(ifnull(a.last_update, a.ctime)) last_update, a.goods * 3+ a.goods_init ups, a.views * 3+ a.views_init play_count, a.reviews comment_count, IF(a.is_essence, 'true', 'false') is_essence, a.type, a.game_id, g.title game_name, UNIX_TIMESTAMP(a.ctime) create_time, a.images FROM articles a LEFT JOIN games g ON g.is_del= 0 AND g.id= a.game_id left join customers c on a.customer_id= c.id where a.is_del= 0 and a.status= 1 AND a.type= 'video' AND a.game_id!= 223 and a.id IN(1)"