default-value

Using class/static methods as default parameter values within methods of the same class

荒凉一梦 提交于 2019-11-30 09:55:16
I'd like to do something like this: class SillyWalk(object): @staticmethod def is_silly_enough(walk): return (False, "It's never silly enough") def walk(self, appraisal_method=is_silly_enough): self.do_stuff() (was_good_enough, reason) = appraisal_method(self) if not was_good_enough: self.execute_self_modifying_code(reason) return appraisal_method def do_stuff(self): pass def execute_self_modifying_code(self, problem): from __future__ import deepjuju deepjuju.kiss_booboo_better(self, problem) with the idea being that someone can do >>> silly_walk = SillyWalk() >>> appraise = walk() >>> is_good

Scala - Currying and default arguments

杀马特。学长 韩版系。学妹 提交于 2019-11-30 08:58:43
I have a function with two parameter lists that I am trying to partially apply and use with currying. The second parameter list contains arguments that all have default values (but not implicit). Something like this: def test(a: Int)(b: Int = 2, c: Int = 3) { println(a + ", " + b + ", " + c); } Now, the following is all fine: test(1)(2, 3); test(1)(2); test(1)(c=3); test(1)(); Now if I define: def partial = test(1) _; Then the following can be done: partial(2, 3); Can someone explain why I can't omit some/all arguments in 'partial' as follows: partial(2); partial(c=3); partial(); Shouldn't

How to set default values with methods in Odoo?

ε祈祈猫儿з 提交于 2019-11-30 07:04:51
How to compute the value for default value in object fields in Odoo 8 models.py We can't use the _default attribute anymore in Odoo 8. field_name = fields.datatype( string=’value’, default=compute_default_value ) In the above field declaration, I want to call a method to assign default value for that field. For example: name = fields.Char( string='Name', default= _get_name() ) You can use a lambda function like this: name = fields.Char( string='Name', default=lambda self: self._get_default_name(), ) @api.model def _get_default_name(self): return "test" A simpler version for the @ChesuCR answer

HTML/PHP - default input value

不想你离开。 提交于 2019-11-30 06:01:09
问题 I have a post php form and a set of inputs: Your Name Your Last Name My Name Every input looks the same, only the names change: <input type="text" name="your_name" value="<?php echo get_option('your_name'); ?>" /> How to set default values when value= is not available? [edit] Ok, so, normally I'd do something like: <input type="text" name="your_name" value="Mike" /> But in this case I have a PHP script that grabs inputs data and displays it using value="<?php echo get_option('your_name'); ?>"

MySQL two column timestamp default NOW value ERROR 1067

谁说我不能喝 提交于 2019-11-30 05:41:49
I have table as shown below. In order to workaround one default now column restriction of MySQL I used the tip as shown here CREATE TABLE IF NOT EXISTS mytable ( id INT NOT NULL AUTO_INCREMENT , create_date TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00' , update_date TIMESTAMP NULL DEFAULT NOW() ON UPDATE NOW() , PRIMARY KEY (`parti_id`) ) ENGINE = InnoDB; My sql_mode does not include NO_ZERO_DATE as pointed here my output : mysql> SELECT @@sql_mode; +------------+ | @@sql_mode | +------------+ | | +------------+ 1 row in set (0.00 sec) It is still giving the error as shown below: ERROR 1067

How do I test a generic type variable for equality with Default(T) in Delphi?

柔情痞子 提交于 2019-11-30 05:10:17
问题 I'm trying to write a generic cached property accessor like the following but am getting a compiler error when trying to check whether the storage variable already contains a value: function TMyClass.GetProp<T>(var ADataValue: T; const ARetriever: TFunc<T>): T; begin if ADataValue = Default(T) then // <-- compiler error on this line ADataValue := ARetriever(); Result := ADataValue; end; The error I'm getting is "E2015 Operator not applicable to this operand type". Would I have to put a

Passing an array as a parameter with default values into int main()

巧了我就是萌 提交于 2019-11-30 03:23:48
问题 I am having difficulty passing an array as an argument into int main() with default values. For example: int main(int a){} works wonderfully. As does int main(int a = 1){} Passing int main() an array also works wonderfully: int main(int a[3]) However, combining these two concepts seems break: int main(int a[1] = {0,1}) After a significant amount of googleing, I haven't found a solution. please help me SO, you're my only hope! EDIT The purpose of this, in short, is to make my code as little

Check to see if a given object (reference or value type) is equal to its default

我是研究僧i 提交于 2019-11-30 03:03:40
I'm trying to find a way to check and see if the value of a given object is equal to its default value. I've looked around and come up with this: public static bool IsNullOrDefault<T>(T argument) { if (argument is ValueType || argument != null) { return object.Equals(argument, default(T)); } return true; } The problem I'm having is that I want to call it like this: object o = 0; bool b = Utility.Utility.IsNullOrDefault(o); Yes o is an object, but I want to make it figure out the base type and check the default value of that. The base type, in this case, is an integer and I want to know in this

Best practice for setting the default value of a parameter that's supposed to be a list in Python?

老子叫甜甜 提交于 2019-11-30 03:02:33
I have a Python function that takes a list as a parameter. If I set the parameter's default value to an empty list like this: def func(items=[]): print items Pylint would tell me "Dangerous default value [] as argument". So I was wondering what is the best practice here? Use None as a default value: def func(items=None): if items is None: items = [] print items The problem with a mutable default argument is that it will be shared between all invocations of the function -- see the "important warning" in the relevant section of the Python tutorial . I just encountered this for the first time,

argparse: setting optional argument with value of mandatory argument

半腔热情 提交于 2019-11-30 01:31:34
问题 With Python's argparse, I would like to add an optional argument that, if not given, gets the value of another (mandatory) argument. parser.add_argument('filename', metavar = 'FILE', type = str, help = 'input file' ) parser.add_argument('--extra-file', '-f', metavar = 'ANOTHER_FILE', type = str, default = , help = 'complementary file (default: FILE)' ) I could of course manually check for None after the arguments are parsed, but isn't there a more pythonic way of doing this? 回答1: As far as I