简体   繁体   中英

Inline comment with line break

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM