Summary: strong/weak typing and pointers
exarkun at divmod.com
exarkun at divmod.com
Thu Nov 4 12:27:42 EST 2004
More information about the Python-list mailing list
Thu Nov 4 12:27:42 EST 2004
- Previous message (by thread): Summary: strong/weak typing and pointers
- Next message (by thread): Summary: strong/weak typing and pointers
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, 4 Nov 2004 17:02:24 +0000 (UTC), Steven Bethard <steven.bethard at gmail.com> wrote: >Diez B. Roggisch <deetsNOSPAM <at> web.de> writes: > > > > I'd second that - writing apus in php can lead to great surprises of what > > actually happens - take this for example: > > > > $foo = "abc"; > > $foo[0] = 65; > > > > The result is > > > > "6bc" > > If I learned nothing else from this thread, I learned that I *never* want to > screw around with PHP. ;) > > > And don't forget: If you don't like the way someone overloaded some > > operator, you can alter that behaviour according to your own design > > philosophies. > > Python has the nice property that you're not allowed to modify builtins, so no > one can ever make your Python code do anything other than: > > >>> foo = 'abc' > >>> foo[0] = 65 > Traceback (most recent call last): > File "<interactive input>", line 1, in ? > TypeError: object does not support item assignment > Not quite. Anything is possible, with the right extension modules: 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' >>> doing-the-impossib-ly yrs, Jp
- Previous message (by thread): Summary: strong/weak typing and pointers
- Next message (by thread): Summary: strong/weak typing and pointers
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list