[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: Use cases for del
From: "George Sakkis" <gsakkis () rutgers ! edu>
Date: 2005-07-07 3:29:45
Message-ID: 1120706984.868966.266710 () g14g2000cwa ! googlegroups ! com
[Download RAW message or body]
"Grant Edwards" wrote:
> In 2005-07-07, Leif K-Brooks <eurl...@ecritters.biz> wrote:
>
> - Hide quoted text -
> - Show quoted text -
> > Grant Edwards wrote:
> >> 1) So I know whether an parameter was passed in or not. Perhaps
> >> it's not considered good Pythonic style, but I like to use a
> >> single method for both get and set operations. With no
> >> parameters, it's a get. With a parameter, it's a set:
>
> >> class demo:
> >> def foo(v=None):
> >> if v is not None:
> >> self.v = v
> >> return self.v
>
> > _NOVALUE = object()
> > class demo:
> > def foo(v=_NOVALUE):
> > if v is _NOVALUE:
> > return self.v
> > else:
> > self.v = v
>
> Apart from the change in the logic such that the set operation
> doesn't return a value, how is that any different? You're just
> creating your own non-integer-value "None" object instead of
> using the one built in to the language.
>
> > But what's wrong with properties?
>
> Huh?
I guess he means why not define foo as property:
class demo(object):
foo = property(fget = lambda self: self.v,
fset = lambda self,v: setattr(self,'v',v))
d = demo()
d.foo = 3
print d.foo
George
--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic