3 ms·
Can it be done for built-in types?
by emehrkay 15y ago
Can it be done for built-in types?
- maaku 15y agoNo, unfortunately. That's one thing both Ruby and JS have over Python.
- oinksoft 15y agoNo, it can't, at least not in CPython. You can import __builtin__ and clobber str, for instance, but that will not affect the behavior of existing strings, nor will it influence the behavior of string literals. It's something that can be done in Ruby and JavaScript, but I believe it was never allowed in Python in the name of performance (you incur overhead when every number is Fixnum with the same lookup rules as any other instance, for example), and also safety.