Summary: strong/weak typing and pointers

exarkun at divmod.com exarkun at divmod.com
Thu Nov 4 13:24:23 EST 2004


On Thu, 4 Nov 2004 17:39:45 +0000 (UTC), Steven Bethard <steven.bethard at gmail.com> wrote:
><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?
> 

  Yep, totally global.  If any code in a process calls replace(), every literal will be an instance of the new type.

  Also, the Python process will segfault at exit, and possibly other times.  This, together with your original comment ("So dirty! ;)") is why I've never bothered releasing the module :)  

  My website (which had a page about the module) has been done for a couple weeks, which may be why google has bumped it from search results.  Probably for the best, really ;)

  Jp



More information about the Python-list mailing list