result = 'function (%s)' % ', '.join(map(str,args))
I recommend a map (str, args) instead of just args, because some of your arguments could potentially not be strings and might raise a TypeError, for example with an int argument in your list:
Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: sequence item 0: expected string, int found
When you fall into dict objects, you probably want a comma to separate the dict values ββ(presumably because the values ββare what you want to pass to this function). If you execute the join method on the dict object itself, you will get keys divided like this:
>>> d = {'d':5, 'f':6.0, 'r':"BOB"} >>> ','.join(d) 'r,d,f'
You want the following:
>>> d = {'d':5, 'f':6.0, 'r':"BOB"} >>> result = 'function (%s)' % ', '.join(map(str, d.values())) >>> result 'function (BOB, 5, 6.0)'
Pay attention to the new problem that you are facing. When you pass a string argument through a join function, it loses its quotation mark. Therefore, if you plan on passing strings, you have lost the quotation marks that would normally surround the string when passed to the function (strings are quoted in many general purpose languages). However, if you only pass numbers, this is not a problem for you.
There is probably a better way to solve the problem I just described, but there is one method here that might work for you.
>>> l = list() >>> for val in d.values(): ... try: ... v = float(val)
Now the line has caves surrounding itself. If you pass in more complex types than numeric primitives and strings, then you probably need a new question :)
One last note: I used d.values ββ() to show how to extract values ββfrom a dictionary, but in fact this will return the values ββfrom the dictionary in almost random order. Since your function most likely requires arguments in a specific order, you must manually create your list of values ββinstead of calling d.values ββ().