args.js
Create javascript functions with optional, default, grouped and named parameters.
Args.js - Optional and Default Parameters for JavaScript
Okay, I've tried searching for this for quite some time. Can I not pass args and kwargs to a view in a django app? Do I necessarily have to define each keyword argument independently?
For example,
#views.py
def someview(request, *args, **kwargs):
...
And while calling the view,
response = someview(request,locals())
I can't seem to be able to do that.
Instead, I have to do:
#views.py
def someview(request, somekey = None):
...
Any reasons why?
Source: (StackOverflow)
I have a string with quotes around the path as follows:
"C:\Program Files (x86)\Windows Media Player\wmplayer.exe" arg1 arg2
If I use Text.Split(new Char[] { ' ' }, 2);
then I get the first space.
How to get the path and args ?
Source: (StackOverflow)
This question already has an answer here:
So I have difficulty with the concept of *args and **kwargs.
So far I have learned that:
*args
= list of arguments -as positional arguments
**kwargs
= dictionary - whose keys become separate keyword arguments and the values become values of these arguments.
??
To be honest I don't understand and don't get for what programming task this would helpful. (I am sure there is, but I can't get an understanding of it.)
Maybe:
I think to enter lists and dictionaries as arguments of a function AND at the same time as a wildcard, so I can pass ANY argument?
Is there a simple example on which to explain how *args
and **kwargs
are used?
Also the tutorial I run through used just the "*" and a variable name.
Is *args
and **kwargs
just a placeholder or do you use exactly *args
and **kwargs
in the code?
Source: (StackOverflow)
We can give parameter args[]
to the main()
method or choose not to. But if we would call any other parameterized method without passing enough arguments, it would give us an error.
Why it is not the case with the main(String[] args)
method?
Source: (StackOverflow)
I can send callback param(s) and it works perfectly as long as I am only sending some primitive types like String. But the same thing does not work for even the simplest POJO. PrimeFaces guide says that the RequestContext.addCallbackParam() method can handle POJOs and it coverts them into JSON. I don't know why it's not working in my case.
Has anybody done that?
Source: (StackOverflow)
In Python I can do this:
def f(a, b, c):
print a, b, c
f(*[1, 2, 3])
How do you say this in PHP?
Source: (StackOverflow)
I've got the following and was wondering if the initial test is overkill:
static void Main(string[] args) {
if (args.Length == 0 || args == null) {
//do X
}
else {
//do Y
}
}
in other words what I'm asking is are there possibilities of args.Length being zero, or args being null....or would just one of these conditions sufficed?
Source: (StackOverflow)
I've been building Wordpress widgets for a while and have always used some code like this:
$instance = wp_parse_args( (array) $instance);
It's never caused problems and is recommended in several places (by Justin Tadlock, two Wordpress books I have, etc.), but none of these sources really explain why.
So, what does this actually do, and what would happen if it was omitted?
Source: (StackOverflow)
This is what I'm looking for:
def __init__(self, *args):
list_of_args = #magic
Parent.__init__(self, list_of_args)
I need to pass *args to a single array, so that:
MyClass.__init__(a, b, c) == Parent.__init__([a, b, c])
Source: (StackOverflow)
I originally made a custom function for timing functions that looks like this:
def timefunc(function, *args):
start = time.time()
data = function(*args)
end = time.time()
time_taken = end - start
print "Function: "+function.__name__
print "Time taken:",time_taken
return data
Now, having learned about the timeit module, I want to implement the same thing using that. I just can't figure out how to do it while sending it the function and *args arguments. I have already figured out that I have to do this in the setup arg:
"from __main__ import function"
But I can't figure out what to do about *args, since both the 'stmt' and 'setup' arguments are strings, how can I pass the variables?
Source: (StackOverflow)
I found this weirdness that I would like to understand. If I define these two methods in pry...
def test(*args)
puts args
end
def test=(*args)
puts args
end
they both work.But if I put the above code in a module and include that module in another class (say, class Job), the following
j=Job.last
j.test=(1,2,3)
throws the following error...
SyntaxError: (irb):3: syntax error, unexpected ',', expecting ')'
j.test=(1,2,3)
^
The following work as expected...
j.test=[1,2,3]
j.test=(1)
So, it looks like inside the module, a method defined with an '=' always expects one arg. That doesn't make sense to me.
What am I missing
Source: (StackOverflow)
I have a dictionary as follows (dict is named channel_info):
{'flume02': u'98.94420000000001', 'flume03': u'32.562999999999995', 'flume01': u'2.15'}
Im trying to loop through the dictionary and report back the values a warning or critical. I have to arguments to the program
parser.add_argument('-w', '--warning', type=int, help='Warning threshold', default=85)
parser.add_argument('-c', '--critical', type=int, help='Critical threshold', default=95)
so basically when i run the program like myprog.py -w 80 -c 90
, i want
flume02 as critical( in this case that would be the only output). If any other key had a value greater than 80 or 90 they would be reported as warning or critical respectively.
However this is not the case and I get all the values under critical.
Relevant code:
if args.warning and not args.critical:
for each in channel_info.items():
if float(each[1]) > float(args.warning):
print 'WARNING | {} is {} percent full'.format(*each)
exit(1)
if args.critical and not args.warning:
for each in channel_info.items():
if float(each[1]) > float(args.critical):
print 'CRITICAL | {} is {} percent full'.format(*each)
exit(2)
if args.warning and args.critical:
for each in channel_info.items():
if float(args.warning) < each[1] < float(args.critical):
print 'WARNING | {} is {} percent full'.format(*each)
elif each[1] > float(args.critical):
print 'CRITICAL | {} is {} percent full'.format(*each)
Output:
CRITICAL | flume02 is 99.9892 percent full
CRITICAL | flume03 is 51.4497 percent full
CRITICAL | flume01 is 7.95 percent full
I put if the last if condition (if args.warning and args.critical
) so to make sure that the program is able to run with either 1 ( -w
or -c
) or both arguments. Any help with what im doing wrong will be greatly appreciated
Source: (StackOverflow)
I need to pass in some args to a groovy script that is executed via the gmaven. I can do this no problem if I execute the script directly on the command line like so:
printArgs.groovy...
for (a in this.args) {
println("Argument: " + a)
}
command...
$groovy printArgs.groovy fe fi fo fum
output...
Argument: fee
Argument: fi
Argument: fo
Argument: fum
I can't see how to pass these args in to via the plugin though using mvn groovy:execute. Ideally, I want to set some default params in the plugin config, but be able to override them when i execute the command. It would be nice to be able to pass them as named-args too if possible.
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<configuration>
<source>${pom.basedir}/src/main/resources/printArgs.groovy</source>
</configuration>
</plugin>
The plugin documentation is a bit scarce (and also outdated). I see there is a 'properties' optional param but I don't think this is to be used for this purpose (or if it is, i can't get it to work!).
Cheers :)
Source: (StackOverflow)
Is it possible to use *args to produce a list of dictionaries where each dictionary has the exact same key and each value is the arg?
For example, I currently have this function:
def Func(word1,word2):
return [{'This is a word':word1},{'This is a word':word2}]
And I use it like so:
print Func("Word1","Word2")
which returns:
[{'This is a word': 'Word1'}, {'This is a word': 'Word2'}]
The issue is that I want to use this Function with 1 word or 5 words. How could I use *args instead? Would starting a function like this be possible:
def Func(*args):
It would be amazing if I could produce the following as well where "This is a word" has the count like so:
[{'This is a word1': 'Word1'}, {'This is a word2': 'Word2'}]
Source: (StackOverflow)
I want to pass more than one record between two forms. The user opens Form-A, selects multiple records and then clicks a button that opens Form-B.
In Form-B there are two (or more) StringEdit
controls and they should display values from the selected records.
I know how to pass only one record, to do that I use the following code in a method of Form-B:
if (element.args().parmEnumType() == enumNum(NoYes)
&& element.args().parmEnum() == NoYes::Yes)
{
myTable = element.args().record();
stringEdit.text(myTable.Field);
}
How should I change my code so that I can set the text of another StringEdit
control to the field value of the next record that the user selected?
Source: (StackOverflow)