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
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
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
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
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
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
>
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
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
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
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
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
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 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
13 matches
Mail list logo