I am using the string and re modules to process text (find striped words in a sentence) to solve a problem on checkIO in Python 2.7. When I run my python script on my computer I receive no error.
text = "My name is ..."
import re, string
init_word_list = re.findall('[A-z0-9]+', text)
word_list = []
for k in init_word_list:
print type(k), repr(k)
if str.isdigit(k):
word_list.append(k)
else:
pass
However, I receive the following TypeError, when I run the same code on checkIO.
TypeError: descriptor 'isdigit' requires a 'str' object but received a `'unicode'`
As you may have noticed, I did insert type() and rep() to figure out what python reads my string as at that point. Here is the output:
<type 'unicode'> u'My'
I would like to know, if I am doing something wrong. Also, what are my options to solve this issue? Should I convert from unicode to ASCII before running the str.isdigit()
function? Or, should I do the alphabet check with the re module? I will venture a guess that people will point me to the checkIO forums to understand why their program is handling the script differently than python running on my computer, but if someone understands this too.. great. :)