当我尝试在形成字符串时运行以下代码时,Python会抛出valueError

时间:2017-11-29 22:20:45

标签: sql string python-2.7 valueerror

index index.html;
root /var/www/domain.com/book;

location = / { 
    return 302 /_book/; 
}
location ^~ /_book/ { 
}
location ~ ^/([^/]+)(/.*)?$ {
    alias /var/www/domain.com/book/$1/_book$2;
    if (!-e $request_filename) { return 302 /; }
}

1 个答案:

答案 0 :(得分:1)

您需要转义%运算符中使用的like字符(加倍),因此python不会尝试对其进行评估:

Query_PNL = """SELECT rptday,extract(year from rptday),extract(month from rptday),a.botid,closetoclosepnl,
                case when closetoclosepnl > 0 then 1
                    when closetoclosepnl < 0 then 0
                END AS PNL_score
                FROM RESEARCH.ADMIN.BOTSDAILYPNL a
                   --order by botid desc, rptday asc;
            right join

                (SELECT marketid,botid,modelid
                FROM RESEARCH.ADMIN.BOTS
                where modelid = 2018 and botname like '%%BackTesting')
                on a.MARKETID = b.marketid and a.BOTID = b.botid
                where a.rptday >='2010-01-01' and a.rptday <='2010-01-31' and a.MARKETID = %s and PNL_score is not null
                order by rptday asc""" %(market)