perl - Cleanest way of choosing between two values in Python -
There is a very good method in python datas get
:
< code> # M to a dict Mkget (a, V) # If M [a] exists, then returns returns, otherwise returns v
is it any value Any way For example, in Perl I can do this:
Return $ some_var or "some_var does not exist."
returning one of the or
operators in Python Its operation, if the left expression evaluates incorrect
, then the correct is evaluated and returned.
Edit :
After reading your question again, I saw that I first misunderstood it. Using the local ()
built-in function, you can use the variable for the get ()
method, as if you use it to decrypt ( Although it is neither very beautiful nor dragon), to check whether a value exists or not:
& gt; & Gt; & Gt; Get local () ('some_var', 'some_var does not exist.') "Some_var does not exist." & Gt; & Gt; & Gt; Some_var = 0> gt; & Gt; & Gt; ('Some_var', 'some_var does not exist.') 0
Comments
Post a Comment