Summary: strong/weak typing and pointers

Steven Bethard steven.bethard at gmail.com
Thu Nov 4 18:39:45 CET 2004


<exarkun <at> divmod.com> writes:
>
> Python 2.3 (#3, Jan 26 2004, 21:50:33)
> [GCC 2.95.3 20010315 (release)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import intrinsics, become
> >>> class phpstr(str):
> ...     def __setitem__(self, index, value):
> ...             become.memwrite(id(self) + 20 + index, str(value)[0])
> ... 
> >>> oldstr = intrinsics.replace(str, phpstr)
> >>> foo = 'abc'
> >>> foo[0] = 65
> >>> foo
> '6bc'

Oooh!  So dirty! ;)

I've never used the intrinsics module (and Googled, but apparently didn't search
for the right thing), but does this do a global replace?  E.g. if my module
imports some module that calls intrinsics.replace(str, phpstr), are all the uses
of str in my module then replaced with phpstr's?

Steve




More information about the Python-list mailing list