Erm, I have ready-to-use code, and I\'m sure it really works, but I get the following error:
TypeError: descriptor \'split\' requires a \'str\' object but
As @Abe mentioned, the problem here is, you are using str.split to split an object of type unicode
which is causing the failure.
There are three options for you
split()
method for the object. This will ensure that irrespective of the type of the object (str
, unicode
), the method call would handle it properly. unicode.split()
. This will work well for unicode
string but for non-unicode
string, this will fail again.split()
function call to method call thus enabling you to transparently call the split()
irrespective if the object type. This is beneficial when you are using the split()
as callbacks esp to functions like map()
The problem is that str.split
is a method of the str
class, but is being called for an object of the unicode
class. Call the method directly with ipSplit = self.serverVars[0].split('.')
to have it work for anything (including str
and unicode
) with a split
method.
Neither method worked when using isdigit
. If you are in a similar solution, you could try a try
-except
block similar to
try:
output += filter(str.isdigit, some_string)
except TypeError:
output += filter(unicode.isdigit, some_string)