带换行符的内联注释
Inline comment with line break
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)
两者都给我编译器问题。有什么想法吗?
只需添加括号:
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)
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)
两者都给我编译器问题。有什么想法吗?
只需添加括号:
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)