variable-assignment

Assign Many Variables at Once, Python

你离开我真会死。 提交于 2019-12-02 06:23:12
Is there a better way to do this? a, b, c, = "yyy", "yyy", "yyy" Obvious attempts fails a, b, c, = "yyy" a, b, c = "yyy"*3 Technically, the following works, but I don't think it's intuitive as this logic says a, b, and c are the same, whereas all I'm trying to do is say they initialize as the same value a=b=c="yyy" No need to use tuple assignment here; the right-hand value is immutable, so you can just as well share the reference: a = b = c = 'yyy' This is not unintuitive at all, in my view, and the python compiler will only need to store one constant with the bytecode, while using tuple

Form validation stops working when I render pages using another controller

早过忘川 提交于 2019-12-02 06:06:48
I wrote a quick CI library class to render my pages so I wouldn't have to keep typing '$this->load->view' all the time and for DRY. Now when I re-render my contact form after passing in invalid data the error messages aren't showing up. The library class: class Page extends CI_Controller { public function render($page, $data) { // $page should be path to page view $this->load->view('fragments/header', $data); $this->load->view('fragments/navigation'); $this->load->view($page); $this->load->view('fragments/navigation'); $this->load->view('fragments/footer'); } } and the controller: class

python assignment in array vs scalar

北城余情 提交于 2019-12-02 04:53:26
I have a 2D array A of shape (4,3) , and a 1D array a of shape (4,) . I want to swap the first two rows of A , as well as the first two elements in a . I did the following: A[0,:],A[1,:] = A[1,:],A[0,:] a[0],a[1] = a[1],a[0] Apparently, it works for a , but fails for A . Now, the second row becomes the first row, but the first row remains unchanged. If I do the following: first_row_copy = A[0,:].copy() A[0,:] = A[1,:] A[1,:] = first_row_copy Then, it seems to work. Why the first method doesn't work? (but works for a ) Also, what's the difference between A_copy = A[0,:].copy() and A_copy = A[0,

Conditionally set a variable if it's NULL

旧街凉风 提交于 2019-12-02 03:17:18
问题 When stepping through a sqlite3_stmt , I'd like to check against a return value of NULL rather than store it and check against the stored value. Here's what I'm doing now: char *email = (char *)sqlite3_column_text(statement, 10); if (email == NULL) email = ""; And here is what I'd like to be doing, minus the double-call to column : char *email = ((char *)sqlite3_column_text(statement, 10)) ? (char *)sqlite3_column_text(statement, 10) : ""; Is there some way to express the second expression

variable is still null after I assign a value to it JAVA

假装没事ソ 提交于 2019-12-02 02:15:21
问题 public void crearCliente() { int i, k, j, l; registro r = new registro(); k = lr.getSize(); for (i = 0; i < k; i++) { r = lr.get(i); l = r.getSize(); String contenido[] = new String[8]; for (j = 0; j < l; j++) { contenido[j] = r.getCampoR(j); //System.out.println(contenido[j]); } c1 = new Cliente(contenido[0], contenido[1], contenido[2], contenido[3], contenido[4], contenido[5], contenido[6], contenido[7]); c1.verCliente();} In this code, at the end,I assign a value to c1, but when I print it

Conditionally set a variable if it's NULL

ε祈祈猫儿з 提交于 2019-12-02 02:09:06
When stepping through a sqlite3_stmt , I'd like to check against a return value of NULL rather than store it and check against the stored value. Here's what I'm doing now: char *email = (char *)sqlite3_column_text(statement, 10); if (email == NULL) email = ""; And here is what I'd like to be doing, minus the double-call to column : char *email = ((char *)sqlite3_column_text(statement, 10)) ? (char *)sqlite3_column_text(statement, 10) : ""; Is there some way to express the second expression more concisely? I have to do a lot of these repetitively, so I'm looking for brevity. I know this is a

variable is still null after I assign a value to it JAVA

淺唱寂寞╮ 提交于 2019-12-02 01:46:54
public void crearCliente() { int i, k, j, l; registro r = new registro(); k = lr.getSize(); for (i = 0; i < k; i++) { r = lr.get(i); l = r.getSize(); String contenido[] = new String[8]; for (j = 0; j < l; j++) { contenido[j] = r.getCampoR(j); //System.out.println(contenido[j]); } c1 = new Cliente(contenido[0], contenido[1], contenido[2], contenido[3], contenido[4], contenido[5], contenido[6], contenido[7]); c1.verCliente();} In this code, at the end,I assign a value to c1, but when I print it i get null in all the c1 fields. I write my code down for the class Cliente. I want to print all the

What is wrong with this assignment in a conditional operator?

梦想的初衷 提交于 2019-12-02 00:33:45
There is an error. Is it wrong to assign a value to a[i] in the following code? Or something is wrong with conditional operators? #include<stdio.h> #include<string.h> int main(){ char a[12]="sumit tyagi"; int i=0; while(a[i]!='\0'){ a[i]>90 ? a[i]=a[i]-32 : a[i]=a[i]+32; //error in this line i++; } printf("\n %s",a); a[i]>90 ? a[i]=a[i]-32 : a[i]=a[i]+32; is not evaluated as a[i]>90 ? (a[i]=a[i]-32) : (a[i]=a[i]+32); since = has lower precedence than ?: . In standard C you can't write it as above although some compilers allow it as an extension. You could write it as the more readable (and

Use strings to create words and paths in Red language

99封情书 提交于 2019-12-02 00:30:25
I have strings in a namelist , that correspond to variables as well as field names in the application. The function should read strings from namelist, add an 'f' to get field_names, and then put variable values in corresponding fields. I tried following code, that does not give any error, but also does not work: namelist: ["var1" "var2"] var1: 5 var2: 10 process: [ repeat i length? namelist [ (to-set-path compose rejoin [namelist/:i "f/text"] (to-word namelist/:i)) ] ] lay: layout [ text "Values to appear here: " var1f: field "a" var2f: field "b" button "Click" [do process] ] view lay As a

Declared but unset variable evaluates as true?

牧云@^-^@ 提交于 2019-12-01 23:07:12
I was doing a simple calculator with the following code. Right now it executes perfectly. When I tried to change things around, however, it doesn't work. I used BOOL program to check whether to continue asking for input from the person or finish the program. If I change the expression of while statement to just (program) and change YES / NO in the program statements, why does the code fail to do what is inside the while ? // A simple printing calculator { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init] Calculator *deskCalc = [[Calculator alloc] init]; double value1; char operator