Here’s the code I have now:
lang = window.get_active_document().get_language()
if lang != None:
lang = lang.get_name()
Is there a better way to do that? I’m new to Pythonic and was wondering if there’s a more Python way to say “something equals this if x is true, else it equals that.”
Thanks.
You could do
lang = lang and lang.get_name()instead of the ‘if’ statement.If lang is None it will stay None. If not, it will be set to lang.get_name().
I’m not sure if that syntax makes things much clearer, though.
P.S. Instead of
lang != Noneyou should usenot lang is None.