【发布时间】:2017-05-15 19:56:28
【问题描述】:
我试图在 HTML 中显示开头有“$”的值,但是我打印出 HTML 中的值的方式使得我只能在前一个的末尾添加它。值或值的末尾。
我想我必须以某种方式将“$”合并到 for 循环中,但我不知道该怎么做。
BODY['html'] += '<br>Total shipped this month:..............Orders........Qty...........Value<br>'
SQL5 = '''
select count(*) as CNT, sum(A.USER_SHIPPED_QTY) as QTY, sum(( A.USER_SHIPPED_QTY) * A.UNIT_PRICE) as VALUE
from SHIPPER_LINE A, SHIPPER B
where B.PACKLIST_ID = A.PACKLIST_ID
and A.CUST_ORDER_ID like ('CO%')
and B.SHIPPED_DATE between ('{}') and ('{}')
'''.format(RP.get_first_of_cur_month_ora(), RP.get_rep_date_ora())
## {} and .format get around the issue of using %s with CO%
print SQL5
curs.execute(SQL5)
for line in curs: ##used to print database lines in HTML
print line
i=0
for c in line:
if i==0:
BODY['html'] += '<pre>' + str(c).rjust(60,' ')
elif i == 1:
BODY['html'] += str(c).rjust(15,' ')
else:
BODY['html'] += str(c).rjust(22,' ') + '</pre>'
i+=1
HTML 中的“pre”用于保留空格,而 rjust 之后的“'”用于正确分隔数字以位于列标题下方。打印出来的值是使用 SQL 从数据库中生成的。
以下是这段代码在 HTML 中显示的内容:
本月总出货量:........订单............数量............价值
3968 16996 1153525.96
这就是我想要的样子:
本月总出货量:........订单............数量............价值
3968 16996 $1153525.96
【问题讨论】:
-
@Jason Heine 我认为我不能在我的情况下使用该代码。我需要在 SQL 或 for 循环中添加一些内容。打印出来的值是使用 SQL 从数据库中生成的