Le mardi 18 octobre 2005 à 19:17 +0200, Antoine Pitrou a écrit : > > What would this mythical block statement look like that would make > > properties easier to write than the above late-binding or the subclass > > Property recipe? > > I suppose something like: > > class C(object): > x = prop: > """ Yay for property x! """ > def __get__(self): > return self._x > def __set__(self, value): > self._x = x
An example of applicating this scheme to Twisted: domain_name = "www.google.com" reactor.resolve(domain_name): def callback(value): print "%s resolves to %s" % (domain_name, value) def errback(error): print "failed to resolve %s!" And then in the Reactor class: def resolve(self, name, @block): ... d = defer.Deferred() cb = block.pop('callback') if cb is not None: d.addCallback(cb) eb = block.pop('errback') if eb is not None: d.addCallback(eb) if block: raise ValueError("spurious blockargs: %s" % str(block)) return d _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com