整数不能用于小数。变通办法?Python

2024-05-13 06:16:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我从一个CSV随机加载到一个类中。我需要系统将其中一个值看作一个数字,而不是用于计算的字符串。这对整数有效。在

class Weapon:
    def __init__ (self, name, value, damage, weight, properties, catagory, description):
        self.name = name
        self.value = int(value)
        self.damage = damage
        self.weight = weight
        self.properties = properties
        self.catagory = catagory
        self.description = description

我有一个问题,如果我尝试对分数使用int(例如0.05),我会得到以下错误:

^{pr2}$

我可以用什么来代替Int,或者和Int一起使用呢?在


Tags: csv字符串nameselfvalue系统数字整数