2

http://legacy.python.org/dev/peps/pep-0008/#maximum-line-length

indicates that we need to not have super long python strings for easy readability. My issue is there is no guide on if you want to break lines and also include an inline comment. I have a long query which is quit ambiguous at first glance. Im trying to clear it up with some inline comments

query = "select jobname,schedtab,odate,order_time,nodeid,state " \
        "from a{0}002_ajob," \ # midrange ajf jobs
        "a{0}003_ajob," \ # mvs ajf jobs
        "a{0}004_ajob," \ # ipo ajf jobs
        "a{0}dv7_ajob" \ # aami ajf jobs
        " where order_time < '{0}' order by odate;".format(date)

I have also tried

query = "select jobname,schedtab,odate,order_time,nodeid,state " \
        # midrange ajf jobs
        "from a{0}002_ajob," \
        # mvs ajf jobs
        "a{0}003_ajob," \
        # ipo ajf jobs
        "a{0}004_ajob," \
        # aami ajf jobs
        "a{0}dv7_ajob" \
        " where order_time < '{0}' order by odate;".format(date)

both give me compiler issues. Any ideas?

jww
  • 97,681
  • 90
  • 411
  • 885
Justin S
  • 1,409
  • 4
  • 22
  • 38
  • See https://docs.python.org/3/reference/lexical_analysis.html#string-literal-concatenation and [this question](http://stackoverflow.com/q/17630835/242583). – livibetter Apr 20 '15 at 03:44

1 Answers1

3

Just add parentheses:

query = ("select jobname,schedtab,odate,order_time,nodeid,state " 
    "from a{0}002_ajob," # midrange ajf jobs
    "a{0}003_ajob," # mvs ajf jobs
    "a{0}004_ajob," # ipo ajf jobs
    "a{0}dv7_ajob" # aami ajf jobs
    " where order_time < '{0}' order by odate;").format(date)

This works too:

query = ("select jobname,schedtab,odate,order_time,nodeid,state " 
    # midrange ajf jobs
    "from a{0}002_ajob," 
    # mvs ajf jobs
    "a{0}003_ajob," 
    # ipo ajf jobs
    "a{0}004_ajob," 
    # aami ajf jobs
    "a{0}dv7_ajob" 
    " where order_time < '{0}' order by odate;").format(date)
S. Adam Nissley
  • 776
  • 1
  • 5
  • 13