By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,537 Members | 1,444 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,537 IT Pros & Developers. It's quick & easy.

setting variables from a tuple NEWB

P: n/a
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

Jul 6 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"manstey" <ma*****@csu.edu.auwrote in message
news:11**********************@q16g2000cwq.googlegr oups.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'
>>>

Jul 6 '06 #2

P: n/a
In <jp*******************@tornado.texas.rr.com>, Paul McGuire wrote:
>>>tupGlob = (('VOWELS','aeiou'),('CONS','bcdfgh'))
for nam,val in tupGlob: locals()[nam]=val
...
>>>VOWELS
'aeiou'
>>>CONS
'bcdfgh'
>>>>
Little warning: It works only on module level as assigning to `locals()`
return value in functions and methods has no effect on the "real" locals.

Ciao,
Marc 'BlackJack' Rintsch
Jul 6 '06 #3

P: n/a

manstey wrote:
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'
could you use a dictionary instead? i.e.
>>tupGlob = {'VOWELS':'aeiou', 'CONS':'bcdfgh'}
tupGlob['VOWELS']
'aeiou'
>>tupGlob['VOWELS'] = 'aeiou AndSometimesY'
tupGlob['VOWELS']
'aeiou AndSometimesY'

nate

Jul 6 '06 #4

P: n/a
On Thu, 06 Jul 2006 04:20:01 -0700, manstey wrote:
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'
Why don't you just do that?

VOWELS = 'aeiou'
CONS = 'bcdfgh'

What benefit do you gain by stuffing your variables into tuples?

--
Steven.

Jul 7 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.