Check yourself


error message:

Traceback (most recent call last):
File "python", line 7, in
TypeError: object of type 'builtin_function_or_method' has no len()

have no idea why it shouldn't work. whatever I tried I keep on getting this error message

print 'Welcome to the Pig Latin Translator!'

# Start coding here!
raw_input(" Enter a word: ")
original = raw_input

if len(original) > 0:
    print original
    print "empty"

variable = function()


variable = function


wow how could I have not seen that. thanks!


do you know however why the error message kept on referring to line 7?


It traces back to the previous line. raw_input is a built-in function, but we wouldn't normally write it without () unless we are passing a function back from another function, to be invoked later.

original = raw_input

Now original is a copy of the function. We can invoke it to perform the same function...

word = original("Enter a word")


>>> original = raw_input
>>> word = original("Enter a word: ")
Enter a word: transference
>>> word


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.