>>>>> mousem...@gmail.com (m) wrote:

>m> Hello all,
>m> I really like the lambda function for a particular task i have: I am
>m> writing some simulation software, working with many different
>m> materials. Each material with many different properties, some are
>m> temperature dependent, others aren't, some are defined by a function,
>m> some are a lookup table, some are constant. Here is a simplified
>m> version:

>m> class material(object):
>m>     def __init__(self,density):
>m>         self.density=density

>m> airdensity=lambda T:100000/(287*T)
>m> air=material(airdensity)

>m> steeldensity=lambda T:interp(T,[0,1000],[7856,7813])
>m> steel=material(steeldensity)

>m> rockdensity=lambda T:5000
>m> rock=material(rockdensity)

The following isn't much different (only 6 chars more per def):
      
def airdensity(T): return 100000/(287*T)
air=material(airdensity)

def steeldensity(T): return interp(T,[0,1000],[7856,7813])
steel=material(steeldensity)

def rockdensity(T): return 5000
rock=material(rockdensity)

-- 
Piet van Oostrum <p...@cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to