When young I was warned repeatedly by more knowledgeable folk that self 
modifying code was dangerous.

Is the following idiom dangerous or unpythonic?

def func(a):
     global func, data
     data = somethingcomplexandcostly()
     def func(a):
         return simple(data,a)
     return func(a)

It could be replaced by

data = somethingcomplexandcostly()
def func(a):
     return simple(data,a)

but this always calculates data.
-- 
Robin Becker
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to