Pyxll:TypeError list indices must be integers or slices,not float

72 Views Asked by At

In excel in cell A1 I have a simple text Hello World.

I write simple UDF function in Pyxll:

from pyxll import xl_func

@xl_func
def get_txt(txt,delimiter,ind):
    l=txt.split(delimiter)
    return l[ind]

example picture

When i call this function in excel =get_txt(A1;" ";0) i get error: TypeError list indices must be integers or slices,not float

But in python this code works fine. Please help how fix this error. Thanks all for help.

1

There are 1 best solutions below

0
olksv On

Thanks everyone, solution found: need to add annotation

from pyxll import xl_func

@xl_func
def get_txt(txt:str,delimiter:str,ind:int)->str:
    l=txt.split(delimiter)
    return l[ind]

but in xlwings it doesn't work((