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


Groups > comp.lang.python > #15561

Re: The python implementation of the "relationships between classes".

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'python': 0.08; '%s"': 0.09; '(there': 0.09; '>>>>': 0.09; 'deletes': 0.09; 'foo': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'nameerror:': 0.09; 'received:gator410.hostgator.com': 0.09; 'weak': 0.09; 'subject:python': 0.11; 'c++': 0.12; 'def': 0.14; '"and': 0.16; 'benjamin': 0.16; 'doe': 0.16; 'inaccessible': 0.16; 'it).': 0.16; 'java.': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'subject:between': 0.16; 'subject:classes': 0.16; 'language': 0.17; 'wrote:': 0.18; 'defined': 0.19; '(most': 0.21; 'header:In- Reply-To:1': 0.23; "python's": 0.24; 'traceback': 0.24; 'print': 0.29; 'class': 0.29; 'object.': 0.30; 'does': 0.32; 'to:addr :python-list': 0.32; 'that,': 0.33; 'there': 0.33; 'header:User- Agent:1': 0.33; 'force': 0.34; 'probably': 0.34; 'last):': 0.34; 'things': 0.35; 'object': 0.35; 'unless': 0.35; 'file': 0.36; 'something': 0.36; 'could': 0.38; 'references': 0.38; 'else': 0.38; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'skip:_ 10': 0.40; 'delete': 0.40; 'received:websitewelcome.com': 0.64; 'received:184': 0.67; 'subject:The': 0.72; '"will': 0.84; "'foo'": 0.84; 'brain,': 0.84; 'reachable': 0.84; 'received:64.5': 0.84; 'us"': 0.84
Date Thu, 10 Nov 2011 12:31:23 -0800
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To python-list@python.org
Subject Re: The python implementation of the "relationships between classes".
References <CANVwdDr-6x8bt4iNL+Q=jZ7+edk7XbR2K_LeJC3Z60qy=vVFQA@mail.gmail.com> <CAPTjJmoOBTiRE8vUNz_xQcwDZA6gazG1fAMkFfhPMomtAKtp6w@mail.gmail.com> <CANVwdDr6qBueBGXykLrhH+MLiwyozD_U1+YRBnrWNfge0=uvDQ@mail.gmail.com> <CAPTjJmqkH6WzbEXWLf6T9yyJyfkH-yCFk1HWd_Vrqwi7iz3FrQ@mail.gmail.com> <CANVwdDqYt+YiJ-hz1F7r+HWnQvFRaJzHvESGoiJu5TKdKE5W7Q@mail.gmail.com> <1320941348.7601.57.camel@tim-laptop> <CANVwdDrZD0Ay7y93uP1r9u+nYS6p==kXq9XZ3m5VHP6w5g1Y+Q@mail.gmail.com> <CAMuTYXj+FOy8tgGAkt-iOUq4O8Ph5-W2OHd=4QSE1OWstu0U0Q@mail.gmail.com>
In-Reply-To <CAMuTYXj+FOy8tgGAkt-iOUq4O8Ph5-W2OHd=4QSE1OWstu0U0Q@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:2633
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2623.1320958355.27778.python-list@python.org> (permalink)
Lines 58
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1320958355 news.xs4all.nl 6988 [2001:888:2000:d::a6]:34921
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:15561

Show key headers only | View raw


Benjamin Kaplan wrote:
> You're still misunderstanding Python's object model. del does NOT
> delete an object. It deletes a name. The only way for an object to be
> deleted is for it to be inaccessible (there are no references to it,
> or there are no reachable references to it).
>>>> foo = object()
>>>> bar = foo
>>>> foo
> <object object at 0x01CE14C0>
>>>> bar
> <object object at 0x01CE14C0>
>>>> del foo
>>>> bar
> <object object at 0x01CE14C0>
>>>> foo
> 
> Traceback (most recent call last):
>   File "<pyshell#7>", line 1, in <module>
>     foo
> NameError: name 'foo' is not defined
> 
> 
> There is no way to force the go_to_heaven method to delete the head
> unless you can make sure that all other references to the head are
> weak references. If you need strictly-enforced relationships, Python
> is probably not the right language for the job- you'll be better off
> with C++ or Java.

Having said all that, you could do something like:

class BodyPart(object):
     _alive = True
     def __nonzero__(self):
         return self._alive
     def die(self):
         self._alive = False

class Head(BodyPart):
     "will contain things like Brain, Eyes, etc"
     size = 5

class Body(BodyPart):
     def __init__(self):
         self._head = Head()
     def go_to_heaven(self):
         self._head.die()
         self.die()

John_Doe = Body()

if John_Doe:
     print "John Doe is alive!"
John_Doe.go_to_heaven()
if John_Doe:
     print "uh oh - something wrong"
else:
     print "John Doe is no longer with us"
     print "and his head is %s" % ('alive' if John_Doe._head else 'dead')

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


Thread

Re: The python implementation of the "relationships between classes". Ethan Furman <ethan@stoneleaf.us> - 2011-11-10 12:31 -0800

csiph-web