Check yourself!


Traceback (most recent call last):
File "python", line 3, in
AttributeError: 'unicode' object has no attribute 'isalpha'

I expect it to print correctly checking to see if there is numbers or not! Can someone tell me what I am doing incorrectly?

print 'Enter a word'
if len(original) > 0 and original.isaplpha() :
    print original
    print "empty"


Two things, first the error...

Check the spelling of the method name.

We can pass the prompt to the function...

original = raw_input("Enter a word: ")

I suspect that writing this...

caused Python to return unicode, and not string data, hence,

AttributeError: 'unicode' object has no attribute 'isalpha'

By including the prompt in string form in the call to raw_input() we must be turning on the String switch. Not sure, but the behavior suggests it. More reading needed (Python 2.7.x).


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