Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Ternary operator alternative in Ptyhon
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="kretik, post: 3569949"] 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 this: self.SomeField = \ params.has_key("mykey") ? params["mykey"] : None) Obviously I know this is not actual Python syntax, but what would be the equivalent? I'm trying to avoid this, basically: if params.has_key("mykey"): self.SomeField = params["mykey"] else: self.SomeField = None This is not a big deal of course, but I guess my main goal is to try and figure out of I'm not missing something more esoteric in the language that lets me do this. Thanks in advance. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Ternary operator alternative in Ptyhon
Top