python modify builtin string functions -


is possible in python modify, or - @ least - deny of execution builtin functions? need, educational purpose, make sure strings split unavailable.

for example, want, if call

'a,b,c'.split(',') 

to throw exception or returned inputed string.

i want force write own version of function. possible?
thanks in advance!

built-in types (str in case) , methods cannot monkey-patched, since implemented in c (for cpython implementation).

however, can define subclass , redefine method:

>>> class mystr(str): ...     def split(self, *args): ...             raise exception("split not defined") ...  >>> mystr("test").split(",") traceback (most recent call last):   file "<stdin>", line 1, in <module>   file "<stdin>", line 3, in split exception: split not defined 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -