I'm trying to make sure an object is a string type in Python (for google app engine). I'm doing this so that I can change it to a db.Text
type if its more than 500 bytes. However, I keep getting the error: TypeError 'unicode' object is not callable
if type(value) in types.StringTypes and len(value) > 499:
value = db.Text(value)
setattr(entity, key, value)
What should I use to test if the type of the object is a string?
I think you just need to remove the parentheses from types.StringTypes
, since it is a tuple (and not callable, hence the error). Either that, or your code is actually using StringType
, which means your code is making a new string instance instead of returning the str
type. Either way, it looks like a typo. See the docs.
Why are you calling types.StringTypes
? It's a tuple:
>>> types.StringTypes
(<type 'str'>, <type 'unicode'>)
Use isinstance(value, types.StringTypes) and len(value) > 499
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With