variable-assignment

How to catch a particular name assignment?

£可爱£侵袭症+ 提交于 2019-12-06 15:02:58
问题 (Based on this question): One can override the __setattr__ magic method for an object to have additional instructions when an attribute of an object is set. As in: class MyClass(object): def __init__(self, attribute=None): object.__init__(self) self.attribute = attribute def __setattr__(self, name, value): self.__dict__[name] = value if name == 'attribute': print("attribute's value is modified to {}.".format( self.attribute)) if __name__ == '__main__': my_obj = MyClass(True) while True: my

Fortran syntax for assignments

馋奶兔 提交于 2019-12-06 14:46:16
The Fortran syntax is driving me mad! Can anyone explain how I can call the assignment (I'm pretty sure that is not the right terminology either...). I'm trying to assign a type according to the value type . I have the following: module test_module implicit none type :: mytype integer :: i real :: r logical :: l contains generic :: assignment(=) => mytype_to_type procedure, pass(me) :: mytype_to_type end type mytype contains subroutine mytype_to_type(t, me) implicit none class(*), intent(inout) :: t class(mytype), intent(in) :: me !.. process based on input type select type (t) type is

In Makefile assign path variable dependent if path exists

社会主义新天地 提交于 2019-12-06 13:29:56
I develop my c++ app alternately on debian and ubuntu and the library root dir of informix database is different on both distributions. What's a nice way of handling it in Makefile so i don't have to change it manually each time? I thought of just testing on existance of the directory so it's more general then checking uname or lsb-release or hostname. And how is the syntax for assigning in a condition? I get the "missing seperator" error on try#2 // prepare INFORMIXDIR_DEB=/usr/informix INFORMIXDIR_UBU=/opt/IBM/informix // tried #1 $(INFORMIXDIR_DEB): if [ -d $(INFORMIXDIR_DEB) ]; then

Use %2* in string variable in Windows batch file

蹲街弑〆低调 提交于 2019-12-06 08:59:03
I'm trying to create a simple script in batch to run in Windows, the script has 3 variables: the URL to open the number of windows to open the time to wait until the new window is open The script works fine except when the URL contains characters like %20 or %2F in which I guess cmd.exe is trying to use them as variables, I'm putting the value of the URL between quotes but that didn't help. If I use the address: set url="http://domain.com/app.html?path=%2F%2Flocalhost%2Fcode&do_pause=false&go=true" the browser opens this: https://domain.com/app.html?path=FFlocalhostFcode&do_pause=false&go=true

Performance: condition testing vs assignment

99封情书 提交于 2019-12-06 07:49:25
I've created a loop where a variable is used to test if the current run-through of the loop is the first one. Its fairly simple: $firstrun = true; while(condition){ if($firstrun) // Do this else // Do that // Change $firstrun to false } I was just wondering (mostly out of curiosity because I'm it makes no real noticeable difference), when I need to change $firstrun to false, would be more efficient to test if the variable is true before assigning it to false or simply reassign it to false during each run-through? Ex: $firstrun = true; while(condition){ if($firstrun) // Do this else // Do that

Assigning an address to a struct pointer array member in C

穿精又带淫゛_ 提交于 2019-12-06 05:49:11
Having considerable trouble with some pointer arithmatic. I think I get the concepts (pointer variables point to a memory address, normal variables point to data) but I believe my problem is with the syntax ( *, &, (*), *(), etc.) What I want to do is build dynamic arrays of a custom struct (i.e. arrays of pointers to heap structs), and my interface provides two methods, "ad_to_obj_array" (which takes the object to add and the array which can be null for empty) and "obj_array_dustbin" (which just takes the array to dispose, also disposing of the contents, the heap objs). The former is rendered

Mass assignment on construction from within ruby [duplicate]

好久不见. 提交于 2019-12-06 05:10:41
This question already has answers here : Closed 9 years ago . Possible Duplicate: Idiomatic object creation in ruby Sometimes it's useful to assign numerous of a constructed arguments to instance variables on construction. Other than the obvious method: def initialize(arg1, arg2, arg3) @arg1, @arg2, @arg3 = arg1, arg2, arg3 end Is there a more concise idiom for achieving the same result? Something like that found in scala for instance: class FancyGreeter(greeting: String) { def greet() = println(greeting) } Where in this case the object FancyGreeter has a default constructor that provides

how to make copy of array instead of reference in java? [duplicate]

随声附和 提交于 2019-12-06 03:20:15
This question already has answers here : How do I do a deep copy of a 2d array in Java? (6 answers) Closed 6 years ago . I want to make an exact copy of given array to some other array but such that even though I change the value of any in the new array it does not change the value in the original array. I tried the following code but after the third line both the array changes and attains the same value. int [][]a = new int[][]{{1,2},{3,4},{5,6}}; int[][] b = a; b[1][0] = 7; instead of the second line I also tried int[][] b = (int[][])a.clone(); int [][] b = new int [3][2]; System.arraycopy(a

Scala parallel assignments only in declarations

こ雲淡風輕ζ 提交于 2019-12-06 02:12:09
问题 Having: def f () = { (1, "two", 3.0) } Why is it ok var (x, y, z) = f() but not var i = 0 var j = "hello" var k = 0.0 // use i, j, k ... //then (i, j, k) = f() // ; expected but = found ? 回答1: You see here a limited version of pattern matching when initializing variables. Note that this works not only for tuples: val a :: b = List(1,2,3) println(a) //1 println(b) //List(2, 3) This feature seems to be borrowed directly from Haskell, where you can use patterns for initialization as well: let (a

Is such assignment a good idea in C++

Deadly 提交于 2019-12-06 01:21:41
A lot of classes has assignment operator (operator=) the same code as in destructor and than very similar code of copy constructor. So is it good idea to implement the assignment in such way? Point& operator=(const Point& point) { if(&point != this) { //Call the destructor this->~Point(); //Make the placement new //Assignment is made because some compilers optimise such code as just // new Point; Point* p_n = new (this) Point(point); //We where placing in this place so pointers should be equal assert(p_n == this); } return *this; } Fred Larson Herb Sutter has addressed this in one of his GotW