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


Groups > comp.lang.python > #65352

Re: __init__ is the initialiser

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'output': 0.05; 'lines,': 0.07; 'none,': 0.07; 'suppose': 0.07; 'tool,': 0.07; '"if': 0.09; 'feature.': 0.09; 'issue:': 0.09; 'line:': 0.09; 'lookup': 0.09; 'references.': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; '"w")': 0.16; '12:50': 0.16; 'dict': 0.16; 'doing,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'garbage': 0.16; 'illustrate': 0.16; 'types,': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'file,': 0.19; 'work,': 0.20; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'source': 0.25; 'references': 0.26; 'required.': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'related': 0.29; 'message-id:@mail.gmail.com': 0.30; 'along': 0.30; "i'm": 0.30; 'everywhere': 0.31; 'object.': 0.31; 'time;': 0.31; 'file': 0.32; 'open': 0.33; '(including': 0.33; 'entirely': 0.33; 'there,': 0.34; 'skip:d 20': 0.34; 'subject:the': 0.34; "i'd": 0.34; 'could': 0.34; "can't": 0.35; 'connection': 0.35; 'problem.': 0.35; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'keyword': 0.36; 'marks': 0.36; 'object,': 0.36; 'done': 0.36; "didn't": 0.36; "i'll": 0.36; 'similar': 0.36; 'turn': 0.37; 'solving': 0.38; 'files': 0.38; 'list,': 0.38; 'resource': 0.38; 'rather': 0.38; 'itself': 0.39; 'sure': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'remove': 0.60; 'easy': 0.60; 'above,': 0.60; 'times': 0.62; 'offer': 0.62; 'kind': 0.63; 'more': 0.64; 'different': 0.65; 'here': 0.66; 'close': 0.67; 'special': 0.74; 'cole': 0.84; 'collection.': 0.84; 'dict.': 0.84; "it'd": 0.84; 'that)': 0.84; 'usage.': 0.84; 'to:none': 0.92
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 :content-type; bh=a/v4dUFgGEf+RFnxFKwFScl1EPSZqGcy3R2NrLQpnms=; b=Nv9SmFjtLer8zb363KlYXR7vPc59RTOT9sIq/AFQevKAlCX6glGyUEt1vJlU/ubmmH garM2Ni4g00DzS0L4y+QeaaK8ZVOe208rObF+NFzRzbET9f8HpuMP7rlxBv26dds2uAR FP3EpM9kJh+3WKfYt07bg3amAMNR9W+PvqAj7+w5jFni2/m+U29rga2y6xq3SPtOdjaJ tUMqxSToLPDw/xVdymHNi1mWhnEJValT7vOuyhh7u2fE0ZsrqS7V8tFDfxsq4yStW2ZA a9K5q3Krr6mZq6pwC1rMWJI5FWYaUIX03/ulNw+RbERsXOjAgRVf9MyJRATyyYYVUfao pvYg==
MIME-Version 1.0
X-Received by 10.68.201.10 with SMTP id jw10mr38890429pbc.25.1391450233440; Mon, 03 Feb 2014 09:57:13 -0800 (PST)
In-Reply-To <CAAu18hevvTDWizx8Gt2S4MUv04KQ0uw7sZaOk-pi-ffsOtG8nw@mail.gmail.com>
References <lcgtpf$tui$1@ger.gmane.org> <lcgut2$b8r$1@ger.gmane.org> <858utviwgs.fsf@benfinney.id.au> <lchce7$44q$1@ger.gmane.org> <52EC3C40.7080402@stoneleaf.us> <mailman.6251.1391224639.18130.python-list@python.org> <52ec84bc$0$29972$c3e8da3$5496439d@news.astraweb.com> <roy-5740C1.00250401022014@news.panix.com> <bl81skFh14iU1@mid.individual.net> <mailman.6313.1391383680.18130.python-list@python.org> <roy-C454F0.18405902022014@news.panix.com> <CAPTjJmo6qpfP74YF+2xKV1y-qUNt6rG+8kHkoYJZXbb3HED5pg@mail.gmail.com> <CAAu18hevvTDWizx8Gt2S4MUv04KQ0uw7sZaOk-pi-ffsOtG8nw@mail.gmail.com>
Date Tue, 4 Feb 2014 04:57:13 +1100
Subject Re: __init__ is the initialiser
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Newsgroups comp.lang.python
Message-ID <mailman.6349.1391450237.18130.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391450237 news.xs4all.nl 2891 [2001:888:2000:d::a6]:41214
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65352

Show key headers only | View raw


On Tue, Feb 4, 2014 at 12:50 AM, Nicholas Cole <nicholas.cole@gmail.com> wrote:
>> There have been occasional times I've wanted an "explicit destruction"
>> feature. Rather than the facetious exception I listed above, it'd be
>> better to have all those references (including the original one in a,
>> since there's nothing special about that) turn into some kind of "null
>> state" - either None, or a special object that marks itself as a
>> destructed/destroyed (terminology debates aside) object. With custom
>> types, I can mark them off with a special flag, and check that all the
>> time; but I can't, for instance, have a dict that maps some lookup
>> keyword to its output file, and then destroy output files to remove
>> all their references from everywhere in the dict. (I have had
>> something along these lines, a bit more complicated than this, but not
>> in Python.)
>
> Can't you get close to that using weakrefs?  I'll admit that care is required.

Weakrefs are a related tool, but solving a different problem. What I
wanted here was an easy way to force all references to a particular
file to be wiped out, based on one of the existing references. Here's
a concocted setup that's broadly similar to what I was doing, which
might illustrate the issue:

log_files = {}

def add_log_file(fn, *keywords):
    f = open(fn, "w")
    for kw in keywords: log_files[kw]=f

for line in process_me_line_generator():
    kw = line.split()[0]
    f = log_files.get(kw)
    if not f: continue
    f.write(line+"\n")
    if 'quit' in line:
        # Okay, let's now close this file.
        destruct(f)


In this particular case, I could use "f.close()" and "if not f or
f.closed: continue", but that requires that the object cooperate in
this way, and I'm not entirely sure about resource usage. (I was
actually working with a database connection object, IIRC, which didn't
offer me a way to inquire if it was still open or not.) To do this
with weak refs, I'd have to have some other source of strong refs, and
closing would be done by digging through that list, disposing of it
from there, and then triggering garbage collection. I suppose it could
be made to work, but it feels like going about everything backwards.

ChrisA

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


Thread

Re: __init__ is the initialiser Terry Reedy <tjreedy@udel.edu> - 2014-01-31 22:16 -0500
  Re: __init__ is the initialiser Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-01 05:23 +0000
    Re: __init__ is the initialiser Roy Smith <roy@panix.com> - 2014-02-01 00:25 -0500
      Re: __init__ is the initialiser Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-03 12:15 +1300
        Re: __init__ is the initialiser Chris Angelico <rosuav@gmail.com> - 2014-02-03 10:27 +1100
          Re: __init__ is the initialiser Roy Smith <roy@panix.com> - 2014-02-02 18:40 -0500
            Re: __init__ is the initialiser Chris Angelico <rosuav@gmail.com> - 2014-02-03 11:07 +1100
            Re: __init__ is the initialiser Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-02-02 17:24 -0800
            Re: __init__ is the initialiser Chris Angelico <rosuav@gmail.com> - 2014-02-03 12:37 +1100
            Re: __init__ is the initialiser Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-02-02 17:54 -0800
            Re: __init__ is the initialiser Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-03 08:44 -0500
            Re: __init__ is the initialiser Nicholas Cole <nicholas.cole@gmail.com> - 2014-02-03 13:50 +0000
            Re: __init__ is the initialiser Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-03 10:44 -0700
            Re: __init__ is the initialiser Chris Angelico <rosuav@gmail.com> - 2014-02-04 04:57 +1100
            Re: __init__ is the initialiser Nicholas Cole <nicholas.cole@gmail.com> - 2014-02-03 19:57 +0000
            Re: __init__ is the initialiser Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-03 19:38 -0500
        Re: __init__ is the initialiser Dave Angel <davea@davea.name> - 2014-02-02 19:35 -0500
          Re: __init__ is the initialiser Roy Smith <roy@panix.com> - 2014-02-02 19:45 -0500
            Re: __init__ is the initialiser Dave Angel <davea@davea.name> - 2014-02-02 22:14 -0500
            Re: __init__ is the initialiser Skip Montanaro <skip@pobox.com> - 2014-02-02 21:15 -0600
            Re: __init__ is the initialiser Dave Angel <davea@davea.name> - 2014-02-03 00:06 -0500
              Re: __init__ is the initialiser Roy Smith <roy@panix.com> - 2014-02-03 00:12 -0500
                Re: __init__ is the initialiser Chris Angelico <rosuav@gmail.com> - 2014-02-03 16:49 +1100
                Re: __init__ is the initialiser Ethan Furman <ethan@stoneleaf.us> - 2014-02-02 21:34 -0800
    Re: __init__ is the initialiser Rustom Mody <rustompmody@gmail.com> - 2014-01-31 21:31 -0800

csiph-web