Python 将数字值传递给函数

Python 将数字值传递给函数,python,python-dragonfly,Python,Python Dragonfly,我想将一个数字值传递给一个函数,但我无法将该值转换为整数。我只能将字符串%(数字)d传递给foo函数 我尝试了许多不同的方法来将语音值转换为一个数字,包括int、float和%(n)d 类代码映射(映射规则): 映射={ “插槽”:foo(“%(数字)d”), “插槽1”:鼠标(“(0.1,0.15),左”), “插槽2”:鼠标(“(0.1,0.2),左”), “插槽3”:鼠标(“(0.1,0.25),左”), “插槽4”:鼠标(“(0.1,0.30),左”), “插槽5”:鼠标(“(0.1,0

我想将一个数字值传递给一个函数,但我无法将该值转换为整数。我只能将字符串%(数字)d传递给foo函数

我尝试了许多不同的方法来将语音值转换为一个数字,包括int、float和%(n)d

类代码映射(映射规则):
映射={
“插槽”:foo(“%(数字)d”),
“插槽1”:鼠标(“(0.1,0.15),左”),
“插槽2”:鼠标(“(0.1,0.2),左”),
“插槽3”:鼠标(“(0.1,0.25),左”),
“插槽4”:鼠标(“(0.1,0.30),左”),
“插槽5”:鼠标(“(0.1,0.35),左”),
“插槽6”:鼠标(“(0.1,0.40),左”),
“插槽7”:鼠标(“(0.1,0.45),左”),
“插槽8”:鼠标(“(0.1,0.50),左”),
}
额外费用=[
整数('number',1,9999),
]

我希望能够向foo方法发送一个语音数字值,并让它返回适当的鼠标坐标。基本上,我应该能够编写一个方法来替换插槽1-插槽8的等效项。

这个问题由Mike Roberts在dragonfly gitter频道上回答。谢谢你,迈克

def foo(slot):
    startingPoint = .15
    increment = .05
    calculation = (slot*increment)
    slotNumber = (startingPoint + calculation) - increment
    return "(0.1, {}), left".format(slotNumber)
class CodeMappings(MappingRule):
    mapping = {  
        'slot <number>': foo('%(number)d'),  
        'slot 1': Mouse("(0.1, 0.15), left"),  
        'slot 2': Mouse("(0.1, 0.2), left"),  
        'slot 3': Mouse("(0.1, 0.25), left"),  
        'Slot 4': Mouse("(0.1, 0.30), left"),  
        'Slot 5': Mouse("(0.1, 0.35), left"),  
        'Slot 6': Mouse("(0.1, 0.40), left"),  
        'Slot 7': Mouse("(0.1, 0.45), left"),  
        'Slot 8': Mouse("(0.1, 0.50), left"),          
    }
    extras=[
        Integer('number', 1, 9999),
    ]