Reputation: 20569
Is it possible in Python to trace and filter functions that are called on strings during program run? I want to add sys.setdefaultencoding("utf-8")
application, and I want to set some guards to predict potential problems with misusing standard functions (like len
, for example), to process such strings.
Upvotes: 1
Views: 94
Reputation: 76611
You can replace the builtin:
import __builtin__
real_len = __builtin__.len
def checked_len(s):
... do extra checks ...
return real_len(s)
__builtin__.len = checked_len
Upvotes: 2