arguments

Is there any way to know if the value of an argument is the default vs. user-specified?

允我心安 提交于 2020-01-19 14:22:27
问题 I'm looking for something that works like Lisp's arg-supplied-p variables, to help differentiate a default value from the same value specified by a user. Example: def foo(a=10): pass I'd like to know in foo if it was called like this: foo() or like this: foo(10) or even like this: foo(a=10) The last 2 are synonymous enough to me; I don't need to know that detail. I've looked through the inspect module a bit, but getargspec returns exactly the same results for all 3 calls. 回答1: Except for

How do I apply unknown arguments to a function in Python 3.x?

梦想与她 提交于 2020-01-16 19:39:39
问题 I'm developing my own GUI for my engine, and I've created an "object" called EwConsole (A simple "drop-down" console to input commands). In order to do that, I simply store an ID for the function to be "triggered with enter/return" as the key to the function-object itself in a dict. My problem is with the arguments, and Python 3.x. Here's my method for creating a new "console command": def create_command(self, command_id, command_function): self["commands"][command_id] = command_function I've

Pass received argument to a callback function

夙愿已清 提交于 2020-01-16 19:32:12
问题 I am working on a Gtk project in C. From the main.c I call a function1 with an int address as a parameter. In that function1 , I can access that first value, but then at the end (inside) of that function1 , I call another function2 (which is a callback function to a click event) and pass it the address I got from the function1 parameter. But in function2 , the address have changed, definitely can't figure out why ... My project looks like this : [main.c] int main(...) { int a = 50; function1(

how to dynamically download a file using struts 2 annotations (passing variable into annotation)

扶醉桌前 提交于 2020-01-16 19:07:02
问题 im new to struts 2 and im asking if there's a way to pass a variable argument into struts 2 annotation. here is what i already did but with no luck public class DownloadFileAction extends ModuleGenericClass{ private InputStream inputStream; private String fileName; @Action(value="/downloadFile",results={ @Result(name="success",type="stream",params = { "contentType", "application/octet-stream", "inputName","inputStream", "bufferSize","1024","contentDisposition", "filename=\"${fileName}\""}) })

how to dynamically download a file using struts 2 annotations (passing variable into annotation)

落花浮王杯 提交于 2020-01-16 19:05:51
问题 im new to struts 2 and im asking if there's a way to pass a variable argument into struts 2 annotation. here is what i already did but with no luck public class DownloadFileAction extends ModuleGenericClass{ private InputStream inputStream; private String fileName; @Action(value="/downloadFile",results={ @Result(name="success",type="stream",params = { "contentType", "application/octet-stream", "inputName","inputStream", "bufferSize","1024","contentDisposition", "filename=\"${fileName}\""}) })

django error: __init__() takes exactly 1 argument (2 given)

二次信任 提交于 2020-01-16 18:43:31
问题 I've written a sqlalchemy model called 'library': class Library(Base): __tablename__ = 'library' id = Column(Integer, primary_key=True) details = Column(String) def __init__(self, details): self.details = details def __repr__(self): return u"Library(%s)" % (self.details) Then, inside the views.py file, I've written: def is_lib_empty(): return len(session.query(Library).all()) <= 0 def populateLib(): new_libs = [Library('one'), Library('two'), Library('three'), Library('four')] session.add_all

django error: __init__() takes exactly 1 argument (2 given)

半腔热情 提交于 2020-01-16 18:43:08
问题 I've written a sqlalchemy model called 'library': class Library(Base): __tablename__ = 'library' id = Column(Integer, primary_key=True) details = Column(String) def __init__(self, details): self.details = details def __repr__(self): return u"Library(%s)" % (self.details) Then, inside the views.py file, I've written: def is_lib_empty(): return len(session.query(Library).all()) <= 0 def populateLib(): new_libs = [Library('one'), Library('two'), Library('three'), Library('four')] session.add_all

Setting conditional(ifelse) arguments in a function

南楼画角 提交于 2020-01-16 06:04:26
问题 I have a simple function and one of its arguments needs to be made conditional, in the sense: IFELSE NOT MISSING take the given value IFELSE NOT EXISTS then give some default value ELSE give the global value of that argument something like this: f <- function(x,y=ifelse(!missing("y"),y,ifelse(!exists("y"),1,get("y",envir=.GlobalEnv)))) { assign("y",y,envir=.GlobalEnv) return(x+y) } required outputs: # :f(3) should give me 4 with global y=1 # :f(4,2) should give me 6 with global y=2 # :f(5)

Why is my mac terminal's ps -u not working?

北城余情 提交于 2020-01-16 02:26:26
问题 I am learning the Linux ps command and its possible arguments. My tutorial told me about the -u argument and I am trying to use it. No matter if I use it alone or with other args, it is throwing errors. I am inserting a picture of the output I keep receiving. I'm not sure if this is something to do with my Mac's terminal/shell, or if I am missing something that I should be typing. It seems to be telling me to use two hyphens, --u, instead of one, -u, but it gives me the same issue. If I JUST

ProcessBuilder won't run with arguments [duplicate]

家住魔仙堡 提交于 2020-01-15 20:16:09
问题 This question already has answers here : Execute with parameters (2 answers) Closed 6 years ago . I am trying to run "java -version" using ProcessBuilder: processBuilder = new ProcessBuilder("java -version"); process = processBuilder.start(); However I get an error: java.io.IOException: Cannot run program "java -version": CreateProcess error=2, The system cannot find the file specified When I remove the "-version" and do: processBuilder = new ProcessBuilder("java"); process = processBuilder