Lambda alternative?

mousemeat mousemeat at gmail.com
Wed Apr 15 12:01:59 EDT 2009


On 15 Apr, 16:27, Piet van Oostrum <p... at cs.uu.nl> wrote:
> >>>>> mousem... at 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... at cs.uu.nl>
> URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
> Private email: p... at vanoostrum.org- Hide quoted text -
>
> - Show quoted text -

Will i then be able to pickle 'rock', and any object that may contain
'rock' as one of it's fields?  I'm not sure that i will, but i'll give
it a shot.



More information about the Python-list mailing list