variable-assignment

Saving a select count(*) value to an integer (SQL Server)

旧街凉风 提交于 2019-12-03 05:04:48
问题 I'm having some trouble with this statement, owing no doubt to my ignorance of what is returned from this select statement: declare @myInt as INT set @myInt = (select COUNT(*) from myTable as count) if(@myInt <> 0) begin print 'there's something in the table' end There are records in myTable, but when I run the code above the print statement is never run. Further checks show that myInt is in fact zero after the assignment above. I'm sure I'm missing something, but I assumed that a select

Assigning a value to a list item using `assign()`

让人想犯罪 __ 提交于 2019-12-03 05:03:23
A little bit of context first... I've written an infix function that in essence replaces the idiom x[[length(x) +1]] <- y ..or simply x <- append(x, y) for vectors. Here it is: `%+=%` <- function(x, y) { xcall <- substitute(x) xobjname <- setdiff(all.names(xcall), c("[[", "[", ":", "$")) # if the object doesn't exist, create it if (!exists(xobjname, parent.frame(), mode = "list") && !exists(xobjname, parent.frame(), mode = "numeric") && !exists(xobjname, parent.frame(), mode = "character")) { xobj <- subset(y, FALSE) } else { xobj <- eval(xcall, envir = parent.frame()) } if (is.atomic(xobj)) {

Set variable in parent scope in Twig

纵然是瞬间 提交于 2019-12-03 03:34:06
In Smarty you can do {$var = 'bla' scope=parent} Is it possible in Twig? Don't suggest to use blocks. I know. I need variable. base.twig <title>{{ title|default('example.com') }} - My cool site</title> child.twig {% set title = 'ChildTitle' %} alexw If you don't want to use the default() filter (i.e., when you want to use the variable multiple times throughout your parent and child templates), you can actually define a block that contains your entire page in the parent template, and then nest your other blocks inside of that: {# base.twig #} {# Default page properties. You can override these

Why does assigning past the end of a list via a slice not raise an IndexError? [duplicate]

落花浮王杯 提交于 2019-12-03 02:36:30
This question already has answers here : Why does substring slicing with index out of range work? (3 answers) I'm working on a sparse list implementation and recently implemented assignment via a slice. This led me to discover some behaviour in Python's built-in list implementation that I find suprising . Given an empty list and an assignment via a slice: >>> l = [] >>> l[100:] = ['foo'] I would have expected an IndexError from list here because the way this is implemented means that an item can't be retrieved from the specified index:: >>> l[100] Traceback (most recent call last): File "

Difference between a -= b and a = a - b in Python

∥☆過路亽.° 提交于 2019-12-03 01:46:51
问题 I have recently applied this solution for averaging every N rows of matrix. Although the solution works in general I had problems when applied to a 7x1 array. I have noticed that the problem is when using the -= operator. To make a small example: import numpy as np a = np.array([1,2,3]) b = np.copy(a) a[1:] -= a[:-1] b[1:] = b[1:] - b[:-1] print a print b which outputs: [1 1 2] [1 1 1] So, in the case of an array a -= b produces a different result than a = a - b . I thought until now that

Assign a print statement to a variable in a function in Python 2.7

蹲街弑〆低调 提交于 2019-12-03 00:55:16
问题 I'm trying to assign a print statement to a variable in a function: def namer(fn, ln='Smith'): # return value, default value r = print "Your name is ", fn, ln return r But when I run the module, it says: Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> import m8 File "m8.py", line 3 r = print "Your name is ", fn, ln ^ SyntaxError: invalid syntax Any explanation? 回答1: As you noted, in Python2.x, print is a statement. A statement is not an object, you cannot assign it

In an assignment A(:) = B, the number of elements in A and B must be the same

你说的曾经没有我的故事 提交于 2019-12-02 22:47:04
问题 if (hidden_layer>1) for i =1 :hidden_layer start_hidden_layer(i) = rand([gk(i+1),(gk(i)+1)])-0.5 ; end end hi Friends. I know every iteration was changed start_hidden_layer matrix dimensional.But all start_hidden_layer values must saved. How to solve this problem? firstly hidden_layer>1 gk(i) is integer value for example 5 , 3, 8 回答1: Since you're calling rand with different matrix sizes on each iteration, you cannot save the results into a normal matrix. You need to use a cell matrix to

Javascript - [Why?] Assigning a variable to an object [duplicate]

▼魔方 西西 提交于 2019-12-02 19:30:54
问题 This question already has answers here : Is JavaScript a pass-by-reference or pass-by-value language? (30 answers) Closed 5 years ago . Why is it that when I assign a variable to an object and make a change to that variable it also changed the objects? For example: c = 26; a = b = c; a += 1; a // 27 b // 26 c // 26 but z = {}; x = y = z; x.ab = 5; x // Object {ab: 5} y // Object {ab: 5} z // Object {ab: 5} Why (in the example above) does y.ab and z.ab exist? I only modified x not y or z .

C assign string from argv[] to char array

二次信任 提交于 2019-12-02 17:44:00
问题 I have the following code which reads an file name from the command line and opens this file: #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv){ FILE *datei; char filename[255]; //filename = argv[1]; //datei=fopen(filename, "r"); datei=fopen(argv[1], "r"); if(datei != NULL) printf("File opened"); else{ printf("Fehler beim öffnen von %s\n", filename); return EXIT_FAILURE; } return EXIT_SUCCESS; } This example works, but I want to write the string from the command line to

Multiple assignment of non-tuples in scala

丶灬走出姿态 提交于 2019-12-02 17:30:34
Just to clarify, when I say multiple assigment, parallel assignment, destructuring bind I mean the following pattern matching gem scala> val (x,y) = Tuple2("one",1) x: java.lang.String = one y: Int = 1 which assigns "one" to x and 1 to y . I was trying to do val (x,y) = "a b".split() I was expecting that scala would attempt to pattern match the array with the pattern, and would throw a runtime exception if the length of the array wouldn't match the length of the pattern. All my attempts to easily convert an Array to a Tuple2 were futile. scala> Tuple2(Array(1,2):_*) <console>:7: error: wrong