title: Python throws valueError when I try to run the following code while forming string
body: <pre><code>import datetime
  from datetime import date
  
  Start_Date = date(2010, 01, 01)
  market = 1
  Query_PNL = """SELECT rptday,extract(year from rptday),extract(month from rptday),a.botid,closetoclosepnl,
                  case when closetoclosepnl &gt; 0 then 1
                      when closetoclosepnl &lt; 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')b
                  on a.MARKETID = b.marketid and a.BOTID = b.botid
                  where a.rptday &gt;='2010-01-01' and a.rptday &lt;='2010-01-31' and a.MARKETID = %s and PNL_score is not null
                  order by rptday asc""" %(market)
  print Query_PNL
  </code></pre>