Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107679

Re: def __init__(self):

Path csiph.com!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!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:30:02 +1000
Lines 23
Message-ID <mailman.121.1461691805.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> <CALvWhxs4wk0c=PQrB7E6+KVQ5=mgo2At7HSP3_5v39t1jgeprw@mail.gmail.com> <CAPTjJmq2MxpR3VZPi5H-4Y6VAXy=1Jcfo7u0x2O2sP7uyzsDMQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de Bm5zXex5oxROZVZH9GqhWgFYuyxNjZ5GHPc6gvNwBsjA==
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; 'cc:addr:python-list': 0.09; 'obj': 0.09; 'python': 0.10; 'def': 0.13; 'wed,': 0.15; 'properly': 0.15; '(val,)': 0.16; '2016': 0.16; 'dummy': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'idx,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:def': 0.16; 'switch.': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'fix': 0.21; 'ctypes': 0.22; 'am,': 0.23; 'this:': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'chris': 0.26; 'message- id:@mail.gmail.com': 0.27; 'object,': 0.27; 'index,': 0.29; 'other,': 0.29; 'handled': 0.29; 'probably': 0.31; 'received:google.com': 0.35; 'skip:c 30': 0.35; 'easiest': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'possible': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'wanted': 0.37; 'received:209': 0.38; 'back': 0.62; 'more': 0.63; 'spend': 0.67; 'actually,': 0.84; 'casting': 0.84; 'chrisa': 0.84; 'subject:self': 0.84; 'to:none': 0.91; 'difficult,': 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=w0Z1MUrRcRhTIRomXPRrY3VBveZYiLNulbb6Sb4dEEA=; b=mfV8ZWXhg+r21KX72CTbRYGpbl1Onu420n1qetD3gMO9kMEdwOg8fUKt81p1Oev5zf 70HMWFfp4Eke/QZSPxWpwJP7ctg9nDIdhtI1knRHl584alWZ01jml48BztUkXwHUAKiR klSNZXmYpXexRonfdsgrS6xhhPdTLr+EQ2yXdHYQA7LVFQyY2YMLZSvZwQtHASz/CUpJ jE54pmlhBgBbQgnbR2z+Y+IkDH0BX+geWYs77D5bwPSlTXRJP2mQ2AOLYtA0/PmYe6+A 2OueodBerjM55NWEPFQjvnrfeZKICFBoOqBCDDVjZDBHLTnytlNSv0vBQsiA4pz+F76i PZWA==
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=w0Z1MUrRcRhTIRomXPRrY3VBveZYiLNulbb6Sb4dEEA=; b=FIOQWn9EFePyRKDpNKUmqxkVegWfBDCVKixqD6Cv89jMoQd0XxxU3ibD+zKe4FhdGu szI3fJWHVf12R1/N3Qd9nL+Tjd6JnALbfxpTGlV3nPkIMymLG89rvUguaTgdn8iJ5gQ2 NkVkd09WPFC4+UIX7NLwvDTKCWNQKauVZPuAVePdOx7mQfJnn5A+RgsoTcz6gwt8qTmt K8G3ntXuPhVqVMCXInWLOc1rMYiA5/aEtMl8yC35cocKerZ0GQcUi9o01XS0ieLGSjid 58Jh7mEUzSW27c2+HtsrzNe39xYfE8Uvnodr1UWlQoK43tntJ39oRuWQi/6HafKVkzkp d9bg==
X-Gm-Message-State AOPr4FXMFpVLRGui8kicCcGrZMHfU1q/VcI1sxqYRSuUWa7VuXCPBafhoXI2gFv9CrYPBaXMTeSigkms5Oh4Hg==
X-Received by 10.107.169.13 with SMTP id s13mr4658964ioe.19.1461691803050; Tue, 26 Apr 2016 10:30:03 -0700 (PDT)
In-Reply-To <CALvWhxs4wk0c=PQrB7E6+KVQ5=mgo2At7HSP3_5v39t1jgeprw@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 <CAPTjJmq2MxpR3VZPi5H-4Y6VAXy=1Jcfo7u0x2O2sP7uyzsDMQ@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> <CAPTjJmoaJWHaXz_6jVoGzCm9Y4C+b5a=4C8gHoxt9B=jxQpJGQ@mail.gmail.com> <CALvWhxs4wk0c=PQrB7E6+KVQ5=mgo2At7HSP3_5v39t1jgeprw@mail.gmail.com>
Xref csiph.com comp.lang.python:107679

Show key headers only | View raw


On Wed, Apr 27, 2016 at 3:13 AM, Chris Kaynor <ckaynor@zindagigames.com> wrote:
> Yah, if you really wanted to make it work properly, you'd need to incref
> the newValue, while decref the oldValue. The incref would not be that
> difficult, but the decref would be more challenging, as you may have to
> also destroy the old object, though that might be possible by casting it
> back to a python object without the incref,. One way or the other, I did
> not exactly spend a ton of time to make it work properly :)

Exactly. :) Actually, the easiest fix is probably this:

import ctypes
def low_change_tuple(tuple, index, newValue):
    obj = ctypes.cast(id(tuple), ctypes.POINTER(ctypes.c_long))
    obj[3+index] = id(newValue)

def change_tuple(tup, idx, val):
    dummy = (val,)
    low_change_tuple(dummy, 0, tup[idx])
    low_change_tuple(tup, idx, val)

Refcounts are handled by the switch.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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