python - 在python中打印布尔值
问题描述
我有一个 json 输入
{
"registryNo":2222904913,
"resgistrySource":"C22",
"DateTime":"None",
"Payments":[{
"Paymentdetail":[
{
"amount":359.95,
"currencyCode":"GBP",
需要生成一个布尔输出来检查货币代码字段是否具有 GBP 值。如果是,则将货币值打印为“True”,否则打印“False”
这是我写的
if "currencycode" in datastore(["Payments"][0]["paymentdetail"]) == "GBP":
print("currencyvalue") = "True" else "FALSE"
——这似乎不起作用。
解决方案
如果我很了解您的问题,您可以尝试这样做:
if "currencycode" in datastore(["Payments"][0]["paymentdetail"][0]):
if datastore(["Payments"][0]["paymentdetail"][0]["currencycode"]) == "GBP":
print("currencyvalue = True")
else:
print("currencyvalue = false")
如果您只想打印“True”或“False”,请执行以下操作:
if "currencycode" in datastore(["Payments"][0]["paymentdetail"][0]):
print(datastore(["Payments"][0]["paymentdetail"][0]["currencycode"]))
对于时间戳,您可以这样做:
from datetime import datetime
dt_object = datetime.fromtimestamp(your_valid_timestamp)
print(dt_object)
推荐阅读
- sql - 获取不带 null 的不同值
- c - 打印与实际答案不同的结果(Ciel 和 AB 问题)
- python - 任务唤醒后上网
- javascript - Angular 中的 Resizable Element 会导致突出显示的文本。如何预防?
- arrays - 如何在 JSX 列中显示数组,而不是一行
- azure - 什么相当于 Azure 中的 Window 服务
- spring-boot - spring security自定义身份验证失败处理程序不转发
- c# - 我应该在哪里清理 ServiceHost 的私有资源?
- python - 如何在 Python 中从 Kubernetes 集群中获取已部署的微服务的 Helm 图表版本
- class - 如何在 Java/Groovy 中基于继承获取类的实例