variables

How to pass a switch parameter as a variable / via splatting in PowerShell?

戏子无情 提交于 2021-02-07 07:16:48
问题 If you have multiple parameters which require a value when calling a command or a script, I know you can pass it like this: $parameters = @{ name = "John" last_name = "Doe" } But if the command or script actually just expect -T to indicate something like a flag, but the parameter itself doesn't require a value. How can I set that in a variable? $optionalT = "" if ($itNeedsTheT) $optionalT = "-T" command $optionalT If I do it like that it complains with the following message: Unknown argument

How to pass a switch parameter as a variable / via splatting in PowerShell?

…衆ロ難τιáo~ 提交于 2021-02-07 07:16:29
问题 If you have multiple parameters which require a value when calling a command or a script, I know you can pass it like this: $parameters = @{ name = "John" last_name = "Doe" } But if the command or script actually just expect -T to indicate something like a flag, but the parameter itself doesn't require a value. How can I set that in a variable? $optionalT = "" if ($itNeedsTheT) $optionalT = "-T" command $optionalT If I do it like that it complains with the following message: Unknown argument

$this->value losing, well, its value

大城市里の小女人 提交于 2021-02-07 06:55:23
问题 I have a problem with a PHP file I'm using, and I can't seem to find a solution. In one part of the code the value for $this->value is set, and the value is set correctly according to my testing. However, later in the same code $this->value is empty. Here's the code: <?php class Padd_Input_Advertisement { protected $keyword; protected $value; protected $name; protected $description; function __construct($keyword,$name,$description='') { $this->keyword = $keyword; $this->value = unserialize

PYTHON: Update MULTIPLE COLUMNS with python variables

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-07 06:13:29
问题 I'm trying to write a valid mysql statement that would allow me to update multiple columns in one record with values provided as python variables. My statement would look like this: db = MySQLdb.connect(host="localhost", user="user", passwd="password", db="dbname") cursor = db.cursor() sql_update = "UPDATE table_name SET field1=%s, field2=%s, field3=%s, field4=%s, field5=%s, field6=%s, field7=%s, field8=%s, field9=%s, field10=%s WHERE id=%s" % (var1, var2, var3, var4, var5, var6, var7, var8,

Initializing Generic Variables in Scala

ぃ、小莉子 提交于 2021-02-07 05:28:29
问题 How do I declare a generic variable in Scala without initializing it (or initializing to any value)? def foo[T] { var t: T = ???? // tried _, null t } 回答1: def foo[T] { var t: T = null.asInstanceOf[T] t } And, if you don't like the ceremony involved in that, you can ease it this way: // Import this into your scope case class Init() implicit def initToT[T](i: Init): T = { null.asInstanceOf[T] } // Then use it def foo[T] { var t: T = Init() t } 回答2: You can't not initialize local variables, but

Do curly braces mean anything in PowerShell variable declaration?

穿精又带淫゛_ 提交于 2021-02-07 04:55:16
问题 I have come across variables (or parameters) being declared like this: ${var_name} = "Hello world!" As far as I can tell, this is no different to the following: $var_name = "Hello world!" I am wondering if the {} braces in the first example do or mean anything. Do they change the behaviour of the variable? 回答1: Curly braces in PowerShell variable names allow for arbitrary characters in the name of the variable. If there are no "pathological" characters in the variable name, then the braces

How to check the type of an awk variable?

一世执手 提交于 2021-02-07 04:20:10
问题 The Beta release of gawk 4.2.0, available in http://www.skeeve.com/gawk/gawk-4.1.65.tar.gz is a major release, with many significant new features . I previously asked about What is the behaviour of FS = " " in GNU Awk 4.2?, and now I noticed the brand new typeof() function to deprecate isarray(): Changes from 4.1.4 to 4.2.0 The new typeof() function can be used to indicate if a variable or array element is an array, regexp, string or number. The isarray() function is deprecated in favor of

How to check the type of an awk variable?

陌路散爱 提交于 2021-02-07 04:18:48
问题 The Beta release of gawk 4.2.0, available in http://www.skeeve.com/gawk/gawk-4.1.65.tar.gz is a major release, with many significant new features . I previously asked about What is the behaviour of FS = " " in GNU Awk 4.2?, and now I noticed the brand new typeof() function to deprecate isarray(): Changes from 4.1.4 to 4.2.0 The new typeof() function can be used to indicate if a variable or array element is an array, regexp, string or number. The isarray() function is deprecated in favor of

Swift Variables Initialization

谁说胖子不能爱 提交于 2021-02-06 11:37:39
问题 I have a question about variables initialization in swift. I have two ways to initialize a variable (as "property" of a class in Objective-C). Which of them is the most correct? class Class { var label: UILabel! init() { ... label = UILabel() ... } } or class Class { var label = UILabel() init() { … } } 回答1: Actually you have 5 ways to initialize properties. There is no correct way, the way depends on the needs. Basically declare objects like UILabel always – if possible – as constant ( let )

Swift Variables Initialization

为君一笑 提交于 2021-02-06 11:34:35
问题 I have a question about variables initialization in swift. I have two ways to initialize a variable (as "property" of a class in Objective-C). Which of them is the most correct? class Class { var label: UILabel! init() { ... label = UILabel() ... } } or class Class { var label = UILabel() init() { … } } 回答1: Actually you have 5 ways to initialize properties. There is no correct way, the way depends on the needs. Basically declare objects like UILabel always – if possible – as constant ( let )