【问题标题】:how to remove the ( ) and , in a floating point如何在浮点中删除 ( ) 和 ,
【发布时间】:2013-01-25 03:11:35
【问题描述】:
latitude = bytes([data[12],data[11],data[10],data[9]])
        longitude = bytes([data[16],data[15],data[14],data[13]])

        intLat = struct.unpack('!f',latitude)
        intLong = struct.unpack('!f',longitude)

        print(intLat) 
        print(intLong)

这是打印的编码。

(100.47630310058594,)
(5.136366844177246,)

如何删除 ( ) 和 , ? 因为我只想将浮动存储在数据库中,没有 out () 和 ,

【问题讨论】:

  • intLat = struct.unpack('!f',latitude)[0] 会做到的!

标签: python floating-point gps latitude-longitude


【解决方案1】:

你必须引用元组的第一个元素:

intLat = struct.unpack('!f',latitude)[0]
intLong = struct.unpack('!f',longitude)[0]

【讨论】:

    【解决方案2】:
    (100.47630310058594,)
    

    这意味着数据是一个只有一个元素的tuple。您可以像对列表一样通过索引来获取数据。

    intLong[0] 
    

    将为您提供数据。

    或者您可以将 unpack 的输出作为 Volatility 提到的索引。

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-29
      相关资源
      最近更新 更多