setting variables from a tuple NEWB
Paul McGuire
ptmcg at austin.rr._bogus_.com
Thu Jul 6 10:48:47 EDT 2006
"manstey" <manstey at csu.edu.au> wrote in message
news:1152184794.016220.234220 at q16g2000cwq.googlegroups.com...
> Hi,
>
> If I have a tuple like this:
>
> tupGlob = (('VOWELS','aeiou'),('CONS','bcdfgh'))
>
> is it possible to write code using tupGlob that is equivalent to:
> VOWELS = 'aeiou'
> CONS = ''bcdfgh'
>
> Thanks,
> Matthew
>
Try this.
-- Paul
>>> tupGlob = (('VOWELS','aeiou'),('CONS','bcdfgh'))
>>> for nam,val in tupGlob: locals()[nam]=val
...
>>> VOWELS
'aeiou'
>>> CONS
'bcdfgh'
>>>
More information about the Python-list
mailing list