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(eval, old) --

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 jenn.du...@gmail.com 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

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

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

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 jenn.du...@gmail.com 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

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 drobi...@gmail.com wrote: On Thu, Aug 18, 2011 at 10:57 AM, noydb jenn.du...@gmail.com 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

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 jenn.du...@gmail.com 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

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 malaclyp...@gmail.com wrote: On Thu, Aug 18, 2011 at 11:19 AM, noydb jenn.du...@gmail.com 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

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 jenn.du...@gmail.com 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

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 gor...@panix.com 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

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 eval(). Eval

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 --

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 gor...@panix.com 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