Python: Using defined arguments with *args -
rewritten make more clear use-case , answer better anentropic's question.
def use_all (step_todo, wait_complete=true, *args): execute_step1 (step-todo) handle_args (*args) if not wait_complete: do_somehing () return execute_stepn () @decorate def use_from (step_todo, *args): use_all (step_todo, args) @decorate def use_many (): use_all (step_todo1, wait_complete=false) use_all (step_todo2, args2) use_all (step_todo3)
the use_all
main "executive" process steps (exactlypxssh
installation). shall not decorated start/stop comments may called several times procedure (e.g. step_many
reboot - reason no wait_complete
), single step shall be.
as use-case specific, may see solution handle *args
_single named variable containing tuple, e.g.
def use_all (step_todo, wait_complete=true, args_list=()):
is correct (and recommended) solution?
this somehow linked questions python function *args , **kwargs other specified keyword arguments or using default arguments before positional arguments . possible not parse kwargs
, keep python r2.7?
thanks jan
you need this:
def use_from(step_todo, *args): use_all(step_todo, *args)
...otherwise calling use_all
single arg containing list of values, instead of calling multiple args
also, don't put space between function , parentheses, it's bad style :)
to around problem of wait_complete
taking value of first arg need pass explicitly, eg:
def use_from(step_todo, *args): use_all(step_todo, true, *args)
Comments
Post a Comment