Python struct.error:' q'范围之外的整数。格式代码

时间:2017-12-11 14:38:38

标签: python struct casting double

我遇到了问题,我想将二进制数转换为双精度数字。

经过一些搜索后,我找到了一些方法,但我仍然遇到问题,我可以演唱"小"数字但不是大数字(双精度),这是我的示例代码:

print unpack( "d", pack( "q", 4631069437225598976 ) )[ 0 ]
print unpack( "d", pack( "q", 13829563286724542464 ) )[ 0 ]

第一个没有问题,但下一个崩溃了描述中的错误。

第一个数字应为:41.7274732 第二个应该是:-0.8899581

有什么想法吗?

非常感谢

1 个答案:

答案 0 :(得分:0)

Name: project-settlement-api-798c8b6688-ldclr Namespace: project Node: 10.93.96.208/10.93.96.208 Start Time: Fri, 10 Nov 2017 18:39:08 -0300 Labels: app=project-settlement-api pod-template-hash=3547462244 run=project Annotations: kubernetes.io/created-by={“kind”:“SerializedReference”,“apiVersion”:“v1",“reference”:{“kind”:“ReplicaSet”,“namespace”:“project”,“name”:“project-settlement-api-798c8b6688”,“uid”:“955c2781-c65f-11e7-ba5... Status: Terminating (expires Fri, 17 Nov 2017 10:25:24 -0300) Termination Grace Period: 0s IP: Created By: ReplicaSet/project-settlement-api-798c8b6688 Controlled By: ReplicaSet/project-settlement-api-798c8b6688 Containers: project-settlement-api: Container ID: Image: Image ID: Port: <none> State: Terminated Exit Code: 0 Started: Mon, 01 Jan 0001 00:00:00 +0000 Finished: Mon, 01 Jan 0001 00:00:00 +0000 Ready: False Restart Count: 0 Environment: SPRING_PROFILES_ACTIVE: docker Mounts: /opt from project-volume (rw) /var/project from project-volume (rw) /var/run/secrets/kubernetes.io/serviceaccount from default-token-qw23t (ro) Conditions: Type Status Initialized True Ready False PodScheduled True Volumes: project-volume: Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace) ClaimName: project-pvc ReadOnly: false QoS Class: BestEffort Node-Selectors: <none> Tolerations: <none> Events: <none> 用于无符号长long,而不是长NAME READY STATUS RESTARTS AGE project-companies-api-5847b84599-6tpbq 0/1 Terminating 0 9m project-companies-api-5847b84599-ph4xl 1/1 Running 0 4m project-companies-api-5847b84599-z5vr2 0/1 Terminating 3 11m project-middleware-85888df786-8nxlj 1/1 Running 0 14d project-settlement-api-5cb5d5859d-qrq8b 1/1 Running 0 2m project-settlement-api-798c8b6688-ldclr 0/1 Terminating 0 20d project-transactions-api-779cd489b7-xvgd8 1/1 Running 0 14d project-users-api-7d7c5cd99d-bqg88 1/1 Running 0 14d project-web-57c869d6fc-7qpk5 1/1 Running 0 14d monitor-app-6455cf9dcf-p4ww4 1/1 Running 0 16m ,将提供所需的输出:

Q

输出:

q

编辑:

请仔细检查其他大数字,因为它可能会出现同样的错误,我们只是在最重要的位置添加一位。