[Tutor] How to map different keys together ?
alan.gauld at btinternet.com
Sun Apr 18 21:23:29 CEST 2010
> My first stumbling block is that M4A files store the track number and
> track total in a single tuple ... but I need them as separate fields
> one of many hurdles -- I need a way to accomplish more than a
> one-to-one data map.
In that case map to a function which can return the value.
Use lambdas for the trivial cases:
'Title': lambda : fileData['title']
For 1-1 maps:
'Artist' : lambda : fileData['ART']
For more complex maps:
'Track' : lambda : flieData['TRK']
'Total' : lambda : fileData['TRK']
And for more complex things define a function:
# do something here
'WeirdThing' : lambda : complex ('WeirdThing')
Then just call the funcyion when needed:
myDatya = map[key]() # parens calls the function
> having trouble. I feel there may be a way to pass functions through
> my tag_map dictionary (maybe a lambda?!) but I can't get my head
> around what approach is best
Does what I've shown make sense?
Author of the Learn To Program website
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor