What would be an effective way to call a function with arguments from a list in python -


my current code similar following.

    def func(args):         optionalparameters = ((args.split(':')[1]).split(' '))[1:]         second_func(optionalparameters) 

this assumes args colon-separated string; takes second half, splits space-delimited words , returns (a list of?) first. situation more 1 colon included isn't yet handled, because new language.

can optional_parameters passed not list? since parameters optional following effective?

    def func(args):         optionalparameters = ((args.split(':')[1]).split(' '))[1:]         val1=val2=val3=none         try:             val1 = optionalparameters[0]         except indexerror:             pass         try:             val2 = optionalparameters[1]         except indexerror:             pass         try:                 val3 = optionalparameters[2]         except indexerror:             pass         second_func(val1, val2, val3) 

it seems standard library modules might able of this. in argument handling highly appreciated.

you can unpack values list:

optionalparameters = ((args.split(':')[1]).split(' '))[1:] second_func(*optionalparameters) 

or:

val1, val2, val3=((args.split(':')[1]).split(' '))[1:]     second_func(val1, val2, val3) 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -