if-statement

JSON JQ if without else

|▌冷眼眸甩不掉的悲伤 提交于 2020-04-08 08:39:34
问题 I use the following JQ command to filter out the JSON. My requirement is to filter out the JSON message if the expected node is present. Or else, do nothing. Hence, I use if, elif, .... sed -n "s/.*Service - //p" $1/response.log* | jq "if (.requests | length) != 0 then .requests |= map(select(.id == \"123\")) elif (.result | length ) != 0 then .result |= map(select(.id== \"123\")) else " " end" > ~/result.log Looks like else is mandatory here. I dont want to do anything inside the else block.

if else function in pandas dataframe [duplicate]

↘锁芯ラ 提交于 2020-04-08 06:43:06
问题 This question already has answers here : Pandas conditional creation of a series/dataframe column (8 answers) Closed 2 years ago . I'm trying to apply an if condition over a dataframe, but I'm missing something (error: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().) raw_data = {'age1': [23,45,21],'age2': [10,20,50]} df = pd.DataFrame(raw_data, columns = ['age1','age2']) def my_fun (var1,var2,var3): if (df[var1]-df[var2])>0 : df[var3]=df[var1]-df

if else function in pandas dataframe [duplicate]

僤鯓⒐⒋嵵緔 提交于 2020-04-08 06:42:30
问题 This question already has answers here : Pandas conditional creation of a series/dataframe column (8 answers) Closed 2 years ago . I'm trying to apply an if condition over a dataframe, but I'm missing something (error: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().) raw_data = {'age1': [23,45,21],'age2': [10,20,50]} df = pd.DataFrame(raw_data, columns = ['age1','age2']) def my_fun (var1,var2,var3): if (df[var1]-df[var2])>0 : df[var3]=df[var1]-df

Difference Between If and Else If?

元气小坏坏 提交于 2020-04-07 12:45:44
问题 I was wondering why you would use an else if statement, and not multiple if statements? For example, what's the difference between doing this: if(i == 0) ... else if(i == 1) ... else if(i == 2) ... And this: if(i == 0) ... if(i == 1) ... if(i == 2) ... They seem to do the exact same thing. 回答1: if(i == 0) ... //if i = 0 this will work and skip following statement else if(i == 1) ...//if i not equal to 0 and if i = 1 this will work and skip following statement else if(i == 2) ...// if i not

how can I avoid the use of #if in a polymorphic print macro

◇◆丶佛笑我妖孽 提交于 2020-04-07 08:01:55
问题 Let's try to run the following code: #include <stdio.h> #define MY_MACRO1(isArray,y) do { \ if(isArray) \ printf("%d", y[0]); \ else \ printf("%d", y); \ }while(0) int main() { int a = 38; int b[]={42}; MY_MACRO1(0,a); return 0; } it returns the error: main.c: In function ‘main’: main.c:12:39: error: subscripted value is neither array nor pointer nor vector printf("%d", y[0]); \ Ok, so we would need a #if statement to run y[0] only if the variable is an array: #define MY_MACRO2(isArray,y) do

how can I avoid the use of #if in a polymorphic print macro

℡╲_俬逩灬. 提交于 2020-04-07 08:01:27
问题 Let's try to run the following code: #include <stdio.h> #define MY_MACRO1(isArray,y) do { \ if(isArray) \ printf("%d", y[0]); \ else \ printf("%d", y); \ }while(0) int main() { int a = 38; int b[]={42}; MY_MACRO1(0,a); return 0; } it returns the error: main.c: In function ‘main’: main.c:12:39: error: subscripted value is neither array nor pointer nor vector printf("%d", y[0]); \ Ok, so we would need a #if statement to run y[0] only if the variable is an array: #define MY_MACRO2(isArray,y) do

Curly braces in if-else blocks

半世苍凉 提交于 2020-04-07 05:37:29
问题 I'm programming in java and I happened to find myself with this: if(nodo == null) return null; else if(nodo.izquierda!=null && nodo.derecha==null) return nodo.izquierda; else if(nodo.izquierda==null && nodo.derecha!=null) return nodo.derecha; else return null; // si ambos hijos son nulos o no nulos My question is: Is it the same to write that as: if(nodo == null) return null; else { if(nodo.izquierda!=null && nodo.derecha==null) return nodo.izquierda; else { if(nodo.izquierda==null && nodo

Why is this else: pass needed for processing to continue? [closed]

ⅰ亾dé卋堺 提交于 2020-04-07 03:44:34
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . Can someone explain why the else: pass shown below is needed in order for the rest of the code (the final print 'processing... statement) to be executed?

Why is this else: pass needed for processing to continue? [closed]

丶灬走出姿态 提交于 2020-04-07 03:44:13
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . Can someone explain why the else: pass shown below is needed in order for the rest of the code (the final print 'processing... statement) to be executed?

Nested 'If' statement in jinja 'for' loop

为君一笑 提交于 2020-03-27 08:37:29
问题 I am trying to sneak in an if statement within a loop for a jinja template: </table> <class="container"> <table border ="1"> <caption> BBOXX <caption> <thead class="thead-inverse"> <tr> <th>CU Serial</th> <th>System</th> <th>Version</th> <th>Enable Status</th> </tr> {% for d in client_data %} <tr> <td>{{ d["serial_number"]}} </td> <td>{{ d["hardware_type"]}} </td> {% if {{ d["current_enable_flag"]}} == TRUE %} <td> {{ON}} </td> {% else %} <td> {{OFF}} </td> {% endif %} </tr> {% endfor %} <