我如何制作1&quot” 1"进入整数?
列表
ValueError Traceback (most recent call last)
<ipython-input-96-93a440c16f3d> in <module>()
38
39 for i in p:
---> 40 Gene.append(int(i.replace(" /gene=","")))
ValueError: invalid literal for int() with base 10: '"1"'
在这种情况下,p < /code>是
[' /gene =“ 1”',' /gene =“ 2”',…] < /code>的 int()不起作用。它不能将
'“ 1”'
变成1
。有没有办法将'“ 1”'
转换为1
?这是什么?
In this case, p
is a list that is [' /gene="1"',' /gene="2"',…]
ValueError Traceback (most recent call last)
<ipython-input-96-93a440c16f3d> in <module>()
38
39 for i in p:
---> 40 Gene.append(int(i.replace(" /gene=","")))
ValueError: invalid literal for int() with base 10: '"1"'
You see, a simple int() doesn't work. It can't turn '"1"'
into 1
. Is there a way to turn '"1"'
into 1
? What is it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将使用
strip()
将这些修剪成像:或偶数:
或者,如果您不想处理平等标志的左侧,请使用分区:
I’d use
strip()
to trim those down like:or even:
or if you don't want to deal with the left side of the equals sign use partition:
您还可以替换报价:
但是,我建议您查看 regex 用于处理解析这样的场景。
You can replace the quotes also:
However, I would recommend looking at RegEx for handling parsing scenarios like this one.
您还必须删除数字周围的报价。
You have to remove the quotes around the number as well.