找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3813|回复: 1

[求助] 求助!Python数据转换!报错:'str' object cannot be interpreted as ...

1

主题

1

帖子

1

积分

贫民

积分
1
hessen 发表于 2019-11-11 11:41:41 | 显示全部楼层 |阅读模式
将数据中的字符串转换成十六进制,老是报错:TypeError:  'str' object cannot be interpreted as an integer
数据举例:
Time    Channel        id_index              Data0
  0.3          1            217056256               3
  0.4          1            419357952              23
  0.5          1            217056256              45
程序:
for each_line in file_data:
            try:
                (Time, Channel, id_index,Data0) = each_line.split(",",3)


                new_id = hex(id_index)
                new_Data0 = hex(Data0)

              print(Time, Channel,new_id,new_Data0,file = file_converted)

要怎么修改呢?菜鸟求助!!在网上找了挺多的数据转换,好像都不行~~~~

回复

使用道具 举报

0

主题

16

帖子

16

积分

贫民

积分
16
edo 发表于 2019-11-21 16:59:54 | 显示全部楼层
(Time, Channel, id_index,Data0) = each_line.split(",",3)
这个得到的 id_index 是 str 类型的

new_id = hex(id_index)
改成 new_id = hex(int(id_index))
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表