On 12/7/2011 7:03 PM, Steven D'Aprano wrote:
On Wed, 07 Dec 2011 09:09:16 -0800, Massi wrote:

Is there a way to create three variables dynamically inside Sum in order
to re write the function like this?

I should have mentioned in my earlier response that 'variable' is a bit vague and misleading. Python has names bound to objects.

def Sum(D) :
     # Here some magic to create a,b,c from D
     return a+b+c

No magic is needed.

a, b, c = D['a'], D['b'], D['c']

This is not what most people mean by 'dynamically created variables'. The names are static, in the code, before the code is executed. In 2.x, 'from x import *' dynamically creates local names that are not in the code that contains the import. Dynamically creating objects is what Python code does all the time.

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to