Skip to content Skip to sidebar Skip to footer

Object Of Type 'function' Has No Len() In Python

I have been searching for a solution for this error for a while but the solutions that have helped others have not been much help for me. Here is the code that I've wrote. def main

Solution 1:

You need to capture the output of userInput():

while True:
    sentence = userInput()
    characterCount(sentence)
    ...

Solution 2:

You are trying to call the function here with a function as an argument.

userInput()
characterCount(userInput)

Instead capture the return value in a variable and call the other function with the variable as an argument.

Example:

def f():
    return 4

def c(f):
    return f 

x = c(f) # <function f at 0x00000231D4063A60>
print(dir(x))   

# ['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

which doesn't have len()

Solution 3:

In Yours code the object userInput has no len(). But object userInput() - has.

Post a Comment for "Object Of Type 'function' Has No Len() In Python"