optional-parameters

How can an optional parameter become required?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 02:41:44
问题 Based on Disable global variable lookup in Python (and my own answer there), I have had problems when using a function with optional parameters such as in this minimal example: import types def noglobal(f): return types.FunctionType(f.__code__, {}) @noglobal def myFunction(x=0): pass myFunction() Essentially, it fails like this: Traceback (most recent call last): File "SetTagValue.py", line 10, in <module> myFunction() TypeError: myFunction() missing 1 required positional argument: 'x' Why is

In any python API documentation, why are optional arguments written in a nested style?

夙愿已清 提交于 2019-12-11 02:41:17
问题 It's just, why do this: find([spec=None[, fields=None[, skip=0[, limit=0[, timeout=True[, snapshot=False[, tailable=False[, sort=None[, max_scan=None[, as_class=None[, slave_okay=False[, await_data=False[, partial=False[, manipulate=True[, read_preference=ReadPreference.PRIMARY[, exhaust=False[, compile_re=True[, **kwargs]]]]]]]]]]]]]]]]]]) Which seems ugly and confusing, yet appears in every api docs I've ever come across, I may lack some basic python knowledge. 回答1: I do not have any

Optional query string parameter passing to WCF service

独自空忆成欢 提交于 2019-12-11 02:24:26
问题 i want to know how to use: string limit = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["Limit"]; in my wcf in this method: CityNewsList GetNewsByCity(string DeviceType,string id,string limit); here 'devicetype' and 'id' are default parameter and what i want is 'limit' as optional parameter means user have a choice to pass this parameter he can pass or can not pass this. want to use limit as: if (limit == some value) { //do this. } if (limit == null) { // do

Optional parameters, “index seek” plan

て烟熏妆下的殇ゞ 提交于 2019-12-11 01:03:23
问题 In my SELECT statement i use optional parameters in a way like this: DECLARE @p1 INT = 1 DECLARE @p2 INT = 1 SELECT name FROM some_table WHERE (id = @p1 OR @p1 IS NULL) AND (name = @p2 OR @p2 IS NULL) In this case the optimizer generates "index scan" (not seek) operations for the entity which is not most effective when parameters are supplied with not null values. If i add the RECOMPILE hint to the query the optimizer builds more effective plan which uses "seek". It works on my MSSQL 2008 R2

Scheme - Optional arguments and default values

不想你离开。 提交于 2019-12-10 21:10:09
问题 I'm currently looking into Scheme, and the way I have understood it, procedures can take an arbitrary number of arguments. I have been trying to play around with this, but I'm struggling to grasp the concept. For instance, say I want to write a welcome message, based on information provided by the user. If user provides a first and last name, the program shout write: Welcome, <FIRST> <LAST>! ;; <FIRST> = "Julius", <LAST>= "Caesar" Welcome, Julius Caesar! Otherwise, the program should refer to

Is using optional parameters for backwards compatibility a good idea?

风流意气都作罢 提交于 2019-12-10 20:04:55
问题 I was wondering about providing backwards compatibility by using optional parameters. In my program I have an interface with a function that is used throughout my program as well as in a lot of unittests. For some new functionality, a boolean has to be passed into this function which will alter its behaviour if set to false . If you pass in true , you will get the same behaviour as before. Now I have to pass in true everywhere where in my current code where I have called this function before.

Why can't Point and Rectangle be used as optional parameters?

这一生的挚爱 提交于 2019-12-10 14:59:16
问题 I'm trying to pass an optional argument to a geometry function, called offset , which may or may not be specified, but C# doesn't allow me to do any of the following. Is there a way to accomplish this? Null as default Error: A value of type '' cannot be used as a default parameter because there are no standard conversions to type 'System.Drawing.Point' public void LayoutRelative(.... Point offset = null) {} Empty as default Error: Default parameter value for 'offset' must be a compile-time

SQL Server stored procedure with optional parameters updates wrong columns

孤人 提交于 2019-12-10 14:53:38
问题 I have a (legacy) VB6 program that needs some work. I have a stored procedure that updates a table of vendors. In this particular form, I don't need to update the entire row, just 10 or so columns out of the 20ish. Here is some pseudo code that works fine if I want to update the entire row: CREATE PROCEDURE [dbo].[spUpdateVendor]( @pID INT, @pVendorID varchar(254), @pVendorName varchar(255), @pContact varchar(255), @pEmail varchar(255), ...) AS BEGIN SET NOCOUNT ON; SET XACT_ABORT ON DECLARE

random.shuffle Randomness

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 14:36:45
问题 I am trying to write a genetic algorithm for homework to solve the travelling salesman problem. One of the mutation functions that I'm trying is to use random.shuffle on the tour. When I read the documentation for random.shuffle , I see: shuffle(self, x, random=None, int=<type 'int'>) method of random.Random instance x, random=random.random -> shuffle list x in place; return None. Optional arg random is a 0-argument function returning a random float in [0.0, 1.0); by default, the standard

How to determine if optional arguments are passed in Ruby

送分小仙女□ 提交于 2019-12-10 13:56:22
问题 If I have the following method in Ruby: def foo(arg1, arg2 = "bar") puts arg1 puts arg2 end Is there a way of determining if a user passed a value in for arg2 within the method? Obviously I could just add if arg2 == "bar" to the method, but this doesn't catch the case where the user manually passed in "bar" herself. Of course, I could set the default to be something that no user would ever pass in, but then that gets pretty ugly pretty quickly. Is there anything elegant out there? 回答1: I am