arguments

Good uses for mutable function argument default values?

时间秒杀一切 提交于 2019-12-28 04:59:09
问题 It is a common mistake in Python to set a mutable object as the default value of an argument in a function. Here's an example taken from this excellent write-up by David Goodger: >>> def bad_append(new_item, a_list=[]): a_list.append(new_item) return a_list >>> print bad_append('one') ['one'] >>> print bad_append('two') ['one', 'two'] The explanation why this happens is here. And now for my question: Is there a good use-case for this syntax? I mean, if everybody who encounters it makes the

Angularjs - Pass argument to directive

人盡茶涼 提交于 2019-12-28 04:59:06
问题 Im wondering if there is a way to pass an argument to a directive? What I want to do is append a directive from the controller like this: $scope.title = "title"; $scope.title2 = "title2"; angular.element(document.getElementById('wrapper')).append('<directive_name></directive_name>'); Is it possible to pass an argument at the same time so the content of my directive template could be linked to one scope or another? here is the directive: app.directive("directive_name", function(){ return {

modify variable within R function

泪湿孤枕 提交于 2019-12-28 02:06:27
问题 How do I modify an argument being passed to a function in R? In C++ this would be pass by reference. g=4 abc <- function(x) {x<-5} abc(g) I would like g to be set to 5. 回答1: There are ways as @Dason showed, but really - you shouldn't ! The whole paradigm of R is to "pass by value". @Rory just posted the normal way to handle it - just return the modified value... Environments are typically the only objects that can be passed by reference in R. But lately new objects called reference classes

find: missing argument to -exec

南笙酒味 提交于 2019-12-28 01:39:49
问题 I was helped out today with a command, but it doesn't seem to be working. This is the command: find /home/me/download/ -type f -name "*.rm" -exec ffmpeg -i {} -sameq {}.mp3 && rm {}\; The shell returns find: missing argument to `-exec' What I am basically trying to do is go through a directory recursively (if it has other directories) and run the ffmpeg command on the .rm file types and convert them to .mp3 file types. Once this is done, remove the .rm file that has just been converted. I

How to deal with name/value pairs of function arguments in MATLAB

瘦欲@ 提交于 2019-12-27 18:20:56
问题 I have a function that takes optional arguments as name/value pairs. function example(varargin) % Lots of set up stuff vargs = varargin; nargs = length(vargs); names = vargs(1:2:nargs); values = vargs(2:2:nargs); validnames = {'foo', 'bar', 'baz'}; for name = names validatestring(name{:}, validnames); end % Do something ... foo = strmatch('foo', names); disp(values(foo)) end example('foo', 1:10, 'bar', 'qwerty') It seems that there is a lot of effort involved in extracting the appropriate

Can I set a default argument from a previous argument?

久未见 提交于 2019-12-27 12:10:49
问题 Is it possible to use previous arguments in a functions parameter list as the default value for later arguments in the parameter list? For instance, void f( int a, int b = a, int c = b ); If this is possible, are there any rules of use? 回答1: The answer is no, you can't. You could get the behaviour you want using overloads: void f(int a, int b, int c); inline void f(int a, int b) { f(a,b,b); } inline void f(int a) { f(a,a,a); } As for the last question, C doesn't allow default parameters at

Swift 4 custom argument labels - required? [closed]

放肆的年华 提交于 2019-12-27 06:03:45
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year . func greet (person person: String, on day: String) -> String { return "Hello \(person) on \(day)" } can be executed as greet ("John", "23") Swift 4 - custom argument labels behave as no argument label - "_" . How to make custom labels mandatory for execution? greet (person: "John", on: "23") Thanks.

Swift 4 custom argument labels - required? [closed]

若如初见. 提交于 2019-12-27 06:03:30
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year . func greet (person person: String, on day: String) -> String { return "Hello \(person) on \(day)" } can be executed as greet ("John", "23") Swift 4 - custom argument labels behave as no argument label - "_" . How to make custom labels mandatory for execution? greet (person: "John", on: "23") Thanks.

In Python, command line args without import?

烂漫一生 提交于 2019-12-25 19:04:49
问题 In Python, is it possible to get the command line arguments without importing sys (or any other module)? 回答1: Yes, if you're using Linux. If you know the process ID, you can read its /proc/{pid}/cmdline file, which contains a null-separated list of the command line arguments: PROCESS_ID = 14766 cmdline = open("/proc/" + str(pid) + "/cmdline").read() print cmdline.split("\0") But it's hard to know the process ID before you start the process. But there's a solution! Look at ALL of the processes

.pubxml - Change variables with Release Definition variables

拈花ヽ惹草 提交于 2019-12-25 16:57:32
问题 I am trying to run my powershell script i pass in all the arguments everything is working but my setParameters.xml file in not changing the Variables from the Realese definition instead it keeps the values from my Release.pubxml file. How could I modify my .pubxml file to have variable/parameters i could change using powershell script. 回答1: Bring all parameters which you wont to replace in this form ParamToReplace Create a environment variable ParamToReplace # read the setParameters.xml file