Unsupported operand type(s) for /: 'unicode' and 'int'


Question

First of all, sorry for making two questions in short interval, but I solved last one so I need help again. I'm coding bukkit plugins with jython/python... I'm pretty new to python/jython and I don't understand where I'm making mistake, take look at the code:

(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

Thanks!

1
1
10/24/2013 8:09:41 PM

Accepted Answer

"It prints 10" doesn't tell you anything about what type it is. It's probably the string "10" and not the number 10 -- as you might guess from the method name getString. You can't divide a string by a number. Try doing:

chance = int(self.cfg.getString("main.candydropchance"))
2
10/24/2013 8:10:35 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon