Thank you everyone. I ended up implementing the dict.get() method, which
seems "cleaner", but I'll keep the (x if y else z) syntax in mind. I
didn't know it existed, I guess it's what I was looking for to begin with.
Thanks again!
Allen wrote:
kretik wrote:
I'm sure this is a popular one, but
jeremie fouche wrote:
> You can also use :
> self.SomeField = params.has_key("mykey") and params["mykey"] or None
Have caution with this solution: it may not provide the desired result in
the case where params["mykey"] is a false value, such as 0, or []
Jeffrey
--
http://mail.python.org/mailman
kretik a écrit :
I'm sure this is a popular one, but after Googling for a while I
couldn't figure out how to pull this off.
I'd like to short-circuit the assignment of class field values passed in
this dictionary to something like this:
self.SomeField = \
params.has_key("mykey") ? pa
kretik wrote:
I'm sure this is a popular one, but after Googling for a while I
couldn't figure out how to pull this off.
Let's say I have this initializer on a class:
def __init__(self, **params):
I'd like to short-circuit the assignment of class field values passed in
this dictionary to
On Tue, 17 Jun 2008 23:18:51 -0700, kretik wrote:
> I'm sure this is a popular one, but after Googling for a while I
> couldn't figure out how to pull this off.
>
> Let's say I have this initializer on a class:
>
> def __init__(self, **params):
Why not ``__init__(self, mykey=None)`` in the
kretik wrote:
I'm sure this is a popular one, but after Googling for a while I
couldn't figure out how to pull this off.
Let's say I have this initializer on a class:
def __init__(self, **params):
I'd like to short-circuit the assignment of class field values passed
in this dictionary to
On Wednesday 18 June 2008, kretik wrote:
> if params.has_key("mykey"):
> self.SomeField = params["mykey"]
> else:
> self.SomeField = None
>
self.SomeField = parms.get('mykey', None)
This looks like what you want and it is also simpler because you don't deal
with che
I'm sure this is a popular one, but after Googling for a while I
couldn't figure out how to pull this off.
Let's say I have this initializer on a class:
def __init__(self, **params):
I'd like to short-circuit the assignment of class field values passed in
this dictionary to something like