python -/: 'unicode' and 'int' 不支持的操作数类型

标签 python int jython bukkit operand

首先,很抱歉在短时间内提出了两个问题,但我解决了最后一个问题,所以我再次需要帮助。我正在使用 jython/python 编写 bukkit 插件...我对 python/jython 还很陌生,我不明白我在哪里犯了错误,看看代码:

(everything is under class hween(PythonPlugin))                      
def CandyChance(self):
    chance = self.cfg.getString("main.candydropchance") #this works, I tried to print it and result is 10 (which I entered in config before)
    chancetotal = chance / 100

@hook.event("block.BlockBreakEvent", "HIGHEST")        
def onBlockBreakEvent(event):
    #something
    chancetotal = pyplugin.CandyChance() 
    if("Random.nextDouble() <= %s"%chancetotal):
       #do something

谢谢!

最佳答案

“It prints 10”并没有告诉你任何关于它是什么类型的信息。它可能是字符串 "10" 而不是数字 10 —— 正如您可能从方法名称 getString 中猜到的那样。您不能将字符串除以数字。尝试这样做:

chance = int(self.cfg.getString("main.candydropchance"))

关于python -/: 'unicode' and 'int' 不支持的操作数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19575650/

相关文章:

Java 编程, 类型转换

python - 转换 Jython 的 source/ast

python - 具有特定格式的 numpy 数组的 Numpy 数组

javascript - 无法从 JQUERY 将 JSON 数据发送到 python

python - 如何在 GAE 任务队列中执行需要 OAuth 的操作?

java - 用户输入字符串和int、if语句

python - 如何在 OpenOffice.Org Calc 的单元格公式中调用 Python 宏?

c++ - 成员引用基类型 'int' 不是结构或 union

java.lang.NoClassDefFoundError : org/python/util/PythonInterpreter

python - 可用的最先进的纯 Python XML 解析器是什么?