Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107673
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: def __init__(self): |
| Date | Wed, 27 Apr 2016 03:04:07 +1000 |
| Lines | 41 |
| Message-ID | <mailman.117.1461690250.32212.python-list@python.org> (permalink) |
| References | <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <mailman.100.1461656092.32212.python-list@python.org> <87lh40pyik.fsf@elektro.pacujo.net> <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> <1461687967.2507874.590200129.102244C8@webmail.messagingengine.com> <mailman.114.1461687970.32212.python-list@python.org> <571f9836$0$1619$c3e8da3$5496439d@news.astraweb.com> <CALvWhxtRM+Qd983o2eB2SC4Hk0EsU26t-zbOQFW23a27Z3gx3Q@mail.gmail.com> <CAPTjJmoaJWHaXz_6jVoGzCm9Y4C+b5a=4C8gHoxt9B=jxQpJGQ@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de oUeNReZygAmyI4EMkvOi6AUUO+8e+O0L/FGwsYIQFA6Q== |
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'cc:addr:python-list': 0.09; '(1,': 0.09; 'immutable': 0.09; 'obj': 0.09; 'def': 0.13; 'suggest': 0.15; 'wed,': 0.15; "'b',": 0.16; '2016': 0.16; '6.0': 0.16; 'ctypes.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'immutable,': 0.16; 'object()': 0.16; 'reason.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subclassing': 0.16; 'subject:def': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'ctypes': 0.22; 'am,': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'chris': 0.26; 'compatible': 0.27; 'message-id:@mail.gmail.com': 0.27; 'index,': 0.29; 'class.': 0.30; 'probably': 0.31; 'anybody': 0.32; "d'aprano": 0.33; 'steven': 0.33; 'tue,': 0.34; 'this?': 0.34; 'received:google.com': 0.35; 'skip:c 30': 0.35; 'something': 0.35; 'received:209.85': 0.36; '(and': 0.36; 'apple': 0.36; 'subject:: ': 0.37; 'things': 0.38; 'doing': 0.38; 'received:209': 0.38; 'mean': 0.38; 'means': 0.39; '26,': 0.72; 'jul': 0.72; 'obvious': 0.76; '4.2.1': 0.84; 'chrisa': 0.84; 'subject:self': 0.84; 'to:none': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=uHEZYMC3Y9D9Iim37XBJMxMW8gpAv1RPXqwOsVPjNgM=; b=MdacLs+W75V6KSC+qYa1YGZ5ehKqpVyydUPdqNkUsHNfE3uUPU6w50D5/KZu5MaKTl Av+aEo2ROLh20sU5E6ydPkfF43ytF/KjdUwxDcbRmpm1pDtN6apZ4rbyowJOxnZVrElY uuhBshyLB5c7GktflRXv/ErPMXybOKSHs+yovAp2eTFq77JPaatC2W55R+sfcEaaXm+l n7e9EeBHp9Hx5Uh6CBzhMF02PyORVzdNXzBU9lxXTCu3tldGFTFwNcz5fc6mSLUcBp8r FLgsy6NDkFBwd1EO24l+WrKctX+sopWsuNwWqqJo2fSpMep5GD3Xx5hrA0Hkih/Gy0Qx FBPA== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=uHEZYMC3Y9D9Iim37XBJMxMW8gpAv1RPXqwOsVPjNgM=; b=S766foerj2O3qXIkVoIiDdPH8UAMDR4ogN1RoWinYEOqzgPszxW5qLyeE4g/aMKAqq J54zx+zREBFSeojZcWmGfS+amess4y6wJuopIbYLZLrY0eNJ6f69ygp0sNWuj5BSn66c aJmbCC7C6eujyAQRZdph7mnu9EHvPfxGt5oyBl+yGkNuwYSoBbzOinl03n8K7SQrQiXk l39ebfHmAIRhTqkJiHDWeLx2AByXPKhoN5L3IX5ihN2sIuwbGiubzC9QEMs+RKmxh1GO isTE7tI/LSI2SPMCC60fRogvbHsULn0PRPPg1scHDzbo/WcNCuXlsvIjkHaCQS3ZhVEI viYQ== |
| X-Gm-Message-State | AOPr4FUVz4gmVG2FjAgZxqJSsAUh40SihIhErtOSsWLyt7OZqBkRNeykPlVe5/EhbnF4/tPvbZuqECSdTm3H2w== |
| X-Received | by 10.107.18.232 with SMTP id 101mr4506599ios.157.1461690247704; Tue, 26 Apr 2016 10:04:07 -0700 (PDT) |
| In-Reply-To | <CALvWhxtRM+Qd983o2eB2SC4Hk0EsU26t-zbOQFW23a27Z3gx3Q@mail.gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <CAPTjJmoaJWHaXz_6jVoGzCm9Y4C+b5a=4C8gHoxt9B=jxQpJGQ@mail.gmail.com> |
| X-Mailman-Original-References | <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <mailman.100.1461656092.32212.python-list@python.org> <87lh40pyik.fsf@elektro.pacujo.net> <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> <1461687967.2507874.590200129.102244C8@webmail.messagingengine.com> <mailman.114.1461687970.32212.python-list@python.org> <571f9836$0$1619$c3e8da3$5496439d@news.astraweb.com> <CALvWhxtRM+Qd983o2eB2SC4Hk0EsU26t-zbOQFW23a27Z3gx3Q@mail.gmail.com> |
| Xref | csiph.com comp.lang.python:107673 |
Show key headers only | View raw
On Wed, Apr 27, 2016 at 2:59 AM, Chris Kaynor <ckaynor@zindagigames.com> wrote:
> On Tue, Apr 26, 2016 at 9:32 AM, Steven D'Aprano <steve@pearwood.info>
> wrote:
>
>> Subclassing immutable built-ins is the most obvious and simple (and
>> probably
>> common) way to get an immutable class. Actually immutable, short of doing
>> wicked things with ctypes.
>>
>
> By wicked things with ctypes, do you mean something like this? By no means
> do I suggest this actually be used by anybody for any reason.
>
> Tested with '2.7.10 (default, Jul 14 2015, 19:46:27) \n[GCC 4.2.1
> Compatible Apple LLVM 6.0 (clang-600.0.39)]'
>
> import ctypes
> def changeTuple(tuple, index, newValue):
> obj = ctypes.cast(id(tuple), ctypes.POINTER(ctypes.c_long))
> obj[3+index] = id(newValue)
>
>>>> a = ('a','b','c')
>>>> changeTuple(a, 0, 1)
>>>> a
> (1, 'b', 'c')
>>>> changeTuple(a, 1, 3)
>>>> a
> (1, 3, 'c')
Yeah. By the look of things, you've just destroyed the reference counts.
>>> a = ('a','b','c')
>>> b = object()
>>> changeTuple(a, 0, b)
>>> a
(<object object at 0x7f1240b22080>, 'b', 'c')
>>> del b
>>> a
Segmentation fault
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
def __init__(self): San <santanu01@gmail.com> - 2016-04-25 23:21 -0700
Re: def __init__(self): Ben Finney <ben+python@benfinney.id.au> - 2016-04-26 16:31 +1000
Re: def __init__(self): Gary Herron <gherron@digipen.edu> - 2016-04-26 00:06 -0700
Re: def __init__(self): Ben Finney <ben+python@benfinney.id.au> - 2016-04-26 17:34 +1000
Re: def __init__(self): Marko Rauhamaa <marko@pacujo.net> - 2016-04-26 11:25 +0300
Re: def __init__(self): Steven D'Aprano <steve@pearwood.info> - 2016-04-27 02:12 +1000
Re: def __init__(self): Random832 <random832@fastmail.com> - 2016-04-26 12:26 -0400
Re: def __init__(self): Steven D'Aprano <steve@pearwood.info> - 2016-04-27 02:32 +1000
Re: def __init__(self): Chris Kaynor <ckaynor@zindagigames.com> - 2016-04-26 09:59 -0700
Re: def __init__(self): Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-04-27 14:54 +1000
Re: def __init__(self): Chris Angelico <rosuav@gmail.com> - 2016-04-27 03:04 +1000
Re: def __init__(self): Chris Kaynor <ckaynor@zindagigames.com> - 2016-04-26 10:13 -0700
Re: def __init__(self): Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-26 11:26 -0600
Re: def __init__(self): Chris Angelico <rosuav@gmail.com> - 2016-04-27 03:30 +1000
Re: def __init__(self): Marko Rauhamaa <marko@pacujo.net> - 2016-04-26 19:38 +0300
Re: def __init__(self): Random832 <random832@fastmail.com> - 2016-04-26 09:49 -0400
Re: def __init__(self): Gary Herron <gherron@digipen.edu> - 2016-04-26 07:25 -0700
csiph-web