带换行符的内联注释

时间:2015-04-20 03:19:58

标签: python-3.x pep8 commenting

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

表示我们不需要超长python字符串以便于阅读。我的问题是,如果你想打破行并且还包括内联注释,则没有指南。我有一个很长的查询,乍一看是不明确的。我试图通过一些内联评论来澄清它

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)

我也试过

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)

都给我编译器问题。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

只需添加括号:

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)

这也有效:

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)