Re: How to convert a list of strings into a list of variables

2011-08-19 Thread noydb
Thanks to all for your responses! Good lessons. I implemented something like what Jerry Hill suggested (dictionary), which works well for my purposes. The list of strings that is being passed into this code is also provided by something I wrote so I do trust what is being sent. Might use what A

Re: How to convert a list of strings into a list of variables

2011-08-19 Thread Roy Smith
In article <2ab25f69-6017-42a6-a7ef-c71bc2ee8...@l2g2000vbn.googlegroups.com>, noydb wrote: > How would you convert a list of strings into a list of variables using > the same name of the strings? > > So, ["red", "one", "maple"] into [red, one, maple] > > Thanks for any help! I'm not sure wh

Re: How to convert a list of strings into a list of variables

2011-08-19 Thread Kingsley Adio
noydb wrote: > How would you convert a list of strings into a list of variables using > the same name of the strings? > > So, ["red", "one", "maple"] into [red, one, maple] > > Thanks for any help! red="a string" one="another string" maple="a file path" old=["red", "one", "maple"] newList=map(ev

Re: How to convert a list of strings into a list of variables

2011-08-18 Thread Steven D'Aprano
Chris Angelico wrote: > On Thu, Aug 18, 2011 at 5:09 PM, John Gordon wrote: >> for x in list_of_strings: >> list_of_variables.append(eval(x)) >> > > If this really is what you need, you can simplify it by using the > globals() dictionary - it's a regular dictionary whose contents are > all the g

Re: How to convert a list of strings into a list of variables

2011-08-18 Thread AB
Hi, If the «variables» are named attributes you can use getattr. # class colors: red=1 green=2 blue=3 c=colors() a=['red','green','blue'] for v in a: print v,getattr(c,v) #--- AB -- http://mail.python.org/mailman/listinfo/pytho

Re: How to convert a list of strings into a list of variables

2011-08-18 Thread Nobody
On Thu, 18 Aug 2011 16:09:43 +, John Gordon wrote: >> How would you convert a list of strings into a list of variables using >> the same name of the strings? > >> So, ["red", "one", "maple"] into [red, one, maple] > > If the strings and the object names are exactly the same, you could use >

Re: How to convert a list of strings into a list of variables

2011-08-18 Thread Chris Angelico
On Thu, Aug 18, 2011 at 5:09 PM, John Gordon wrote: > for x in list_of_strings: >    list_of_variables.append(eval(x)) > If this really is what you need, you can simplify it by using the globals() dictionary - it's a regular dictionary whose contents are all the global variables in your current m

Re: How to convert a list of strings into a list of variables

2011-08-18 Thread John Gordon
In <2ab25f69-6017-42a6-a7ef-c71bc2ee8...@l2g2000vbn.googlegroups.com> noydb writes: > How would you convert a list of strings into a list of variables using > the same name of the strings? > So, ["red", "one", "maple"] into [red, one, maple] > Thanks for any help! If the strings and the objec

Re: How to convert a list of strings into a list of variables

2011-08-18 Thread noydb
On Aug 18, 11:29 am, Jerry Hill wrote: > On Thu, Aug 18, 2011 at 11:19 AM, noydb wrote: > > I am being passed the list of strings.  I have variables set up > > already pointing to files.  I need to loop through each variable in > > the list and do things to the files.  The list of strings will ch

Re: How to convert a list of strings into a list of variables

2011-08-18 Thread Jerry Hill
On Thu, Aug 18, 2011 at 11:19 AM, noydb wrote: > I am being passed the list of strings.  I have variables set up > already pointing to files.  I need to loop through each variable in > the list and do things to the files.  The list of strings will change > each time, include up to 22 of the same s

Re: How to convert a list of strings into a list of variables

2011-08-18 Thread noydb
On Aug 18, 11:12 am, David Robinow wrote: > On Thu, Aug 18, 2011 at 10:57 AM, noydb wrote: > > How would you convert a list of strings into a list of variables using > > the same name of the strings? > > > So, ["red", "one", "maple"] into [red, one, maple] > >   Why would you want to? I am being

Re: How to convert a list of strings into a list of variables

2011-08-18 Thread David Robinow
On Thu, Aug 18, 2011 at 10:57 AM, noydb wrote: > How would you convert a list of strings into a list of variables using > the same name of the strings? > > So, ["red", "one", "maple"] into [red, one, maple] Why would you want to? -- http://mail.python.org/mailman/listinfo/python-list

How to convert a list of strings into a list of variables

2011-08-18 Thread noydb
How would you convert a list of strings into a list of variables using the same name of the strings? So, ["red", "one", "maple"] into [red, one, maple] Thanks for any help! -- http://mail.python.org/mailman/listinfo/python-list