FAQ

Nick Coghlan wrote:
Killer app for this keyword:

class C(object):

x = property(get, set) where:
def get(self):
return "Silly property"
def set(self, val):
self.x = "Told you it was silly"
Hey, this is super-elegant!

AdSR


From http Sat Jan 8 11:34:08 2005
From: http (Paul Rubin)
Date: 08 Jan 2005 02:34:08 -0800
Subject: python3: 'where' keyword
References: <3480qqF46jprlU1@individual.net> <41DF78EB.6040502@iinet.net.au>
<mailman.357.1105166539.22381.python-list@python.org>
<crocp2$gv6$1@news.onet.pl>
Message-ID: <7xhdlsw6ov.fsf@ruckus.brouhaha.com>

AdSR <adsr at poczta.onet.pl> writes:
Killer app for this keyword:
class C(object):
x = property(get, set) where:
def get(self):
return "Silly property"
def set(self, val):
self.x = "Told you it was silly"
Hey, this is super-elegant!
Heh, even further:

z = C() where:
class C(object):
...

Lets you make anonymous classes and singleton objects.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

People

Translate

site design / logo © 2022 Grokbase