1. 程式人生 > >python ValueError: unsupported format character ''' (0x27) at index 224

python ValueError: unsupported format character ''' (0x27) at index 224

問題:將sql語句從mysql複製到python,報錯 ValueError: unsupported format character ''' (0x27) at index 224

sql = "select   concat(round(bid_rate*100,2),'%') as bid_rate from platform_bid_day where section BETWEEN  '%s' and  '%s' ORDER BY section  " % (st,et)
 

解決:將%換成%%,如下

sql = "select   concat(round(bid_rate*100,2),'%%

') as bid_rate from platform_bid_day where section BETWEEN  '%s' and  '%s' ORDER BY section  " % (st,et)