Python 杂记(1)

记录一些琐碎的结果


查看 sqlalchemy query_odj 生成的原生sql语句
# 方案1
echo=True

# 方案2
print q.statement.compile()

聚合字段重命名
# python sqlalchemy
func.sum(TableModel.field).label('new_name')

decimal类型数据保留两位
# price type: decimal.Decimal
str(price.quantize(decimal.Decimal('0.00')))

多异常捕获
try:
    ...
except (JackException, BobException) as e:
    pass

py2 str() 报错时
try:
    ...
except Exception as e:
    log.error(str(e))

# new
import six
try:
    ...
except Exception as e:
    log.error(six.text_type(e))


OpenStack消息监听,如果目标 'exchange'、'routing-key' 无法获取到资源uuid ,请求id也是不错的替代品
msg['payload']['instance_id'] = 70e88716-98ff-4fe1-bc32-d4c6fd176c18

msg['_context_request_id'] = req-21b30fb5-6577-4e34-bb75-a3a41004df1d

按官网构建原生OpenStack,完成后 'cinder' 下只有 'notifications.*' 的routing-key
# /etc/cinder/cinder.conf

[DEFAULT]
control_exchange = cinder

posted on 2021-07-30 17:33  〆灬丶  阅读(33)  评论(0编辑  收藏  举报