Re: Variable definition

2010-03-01 Thread Rhodri James
On Mon, 01 Mar 2010 18:07:17 -, Raphael Mayoraz wrote: Thanks for your answer. However, your solution changes the key name in the dictionary. That's not what I want I need to do. What I want is to define a new variable which name is define as a string: 'myPrefx' + key. In the example I

Re: Variable definition

2010-03-01 Thread John Posner
On 3/1/2010 1:07 PM, Raphael Mayoraz wrote: John Posner wrote: On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: Hello, I'd like to define variables with some specific name that has a common prefix. Something like this: varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} for key, value in varDic.iter

Re: Variable definition

2010-03-01 Thread Raphael Mayoraz
John Posner wrote: On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: Hello, I'd like to define variables with some specific name that has a common prefix. Something like this: varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} for key, value in varDic.iteritems(): 'myPrefix' + key = value No trick

Re: Variable definition

2010-02-27 Thread Andreas Waldenburger
On 27 Feb 2010 03:33:57 GMT Steven D'Aprano wrote: > exec "'myPrefix_turquoise' = 42" > Not quite: In [1]: exec "'myPrefix_turquoise' = 42" File "", line 1 SyntaxError: can't assign to literal (, line 1) I think you meant: exec

Re: Variable definition

2010-02-26 Thread Dave Angel
Steven D'Aprano wrote: for key, value in varDic.iteritems(): varDic['myPrefix_' + key] = value del varDic[key] Watch out if any of the existing values already startswith 'myPrefix' You can end up with trouble just as confusing as if 'myPrefix' is an empty string DaveA -- http:/

Re: Variable definition

2010-02-26 Thread Steven D'Aprano
On Fri, 26 Feb 2010 15:32:27 -0800, Raphael Mayoraz wrote: > Hello, > > I'd like to define variables with some specific name that has a common > prefix. > Something like this: > > varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} > for key, value in varDic.iteritems(): > 'myPrefix' + key = va

Re: Variable definition

2010-02-26 Thread John Posner
On 2/26/2010 10:20 PM, Steven D'Aprano wrote: On Fri, 26 Feb 2010 20:15:16 -0500, John Posner wrote: On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: Hello, I'd like to define variables with some specific name that has a common prefix. Something like this: varDic = {'red': 'a', 'green': 'b', 'bl

Re: Variable definition

2010-02-26 Thread Steven D'Aprano
On Fri, 26 Feb 2010 20:15:16 -0500, John Posner wrote: > On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: >> Hello, >> >> I'd like to define variables with some specific name that has a common >> prefix. >> Something like this: >> >> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} for key, value in >

Re: Variable definition

2010-02-26 Thread John Posner
On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: Hello, I'd like to define variables with some specific name that has a common prefix. Something like this: varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} for key, value in varDic.iteritems(): 'myPrefix' + key = value No trick, just swap a new ke

Re: Variable definition

2010-02-26 Thread alex goretoy
On Fri, Feb 26, 2010 at 6:22 PM, Alf P. Steinbach wrote: > * Raphael Mayoraz: > >> Hello, >> >> >> I'd like to define variables with some specific name that has a common >> prefix. >> Something like this: >> >> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} >> for key, value in varDic.iteritems

Re: Variable definition

2010-02-26 Thread Alf P. Steinbach
* Raphael Mayoraz: Hello, I'd like to define variables with some specific name that has a common prefix. Something like this: varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} for key, value in varDic.iteritems(): 'myPrefix' + key = value I know this is illegal, but there must be a trick s

Re: Variable definition

2010-02-26 Thread Rhodri James
On Fri, 26 Feb 2010 23:32:27 -, Raphael Mayoraz wrote: I'd like to define variables with some specific name that has a common prefix. Why? No seriously, how do you think this is going to solve whatever problem you clearly think it will solve? -- Rhodri James *-* Wildebeeste Herder