Re: [Tutor] accessing list from a string

2008-11-26 Thread Alan Gauld
John Fouhy [EMAIL PROTECTED] wrote s = [2.5,2.8] # your string from the file e = tuple( + e + ) This should of course be e = tuple( + s + ) If I, as an evildoer, can control e, it seems that I could set it to: ,), __import__('os').system('rm -rf /' Assuming you now mean s

Re: [Tutor] accessing list from a string

2008-11-26 Thread Alan Gauld
John Fouhy [EMAIL PROTECTED] wrote e = tuple( + e + ) x,y = eval(e)# x - 2.5, y - 2.8 If I, as an evildoer, can control e, it seems that I could set it to: ,), __import__('os').system('rm -rf /' I've never thought of myself as all that devious :-) Sorry John, too fast in

Re: [Tutor] accessing list from a string

2008-11-26 Thread Kent Johnson
On Wed, Nov 26, 2008 at 4:16 AM, Alan Gauld [EMAIL PROTECTED] wrote: John Fouhy [EMAIL PROTECTED] wrote e = tuple( + e + ) x,y = eval(e)# x - 2.5, y - 2.8 If I, as an evildoer, can control e, it seems that I could set it to: ,), __import__('os').system('rm -rf /' But that would

Re: [Tutor] accessing list from a string

2008-11-26 Thread Alan Gauld
Kent Johnson [EMAIL PROTECTED] wrote e = tuple( + s + ) x,y = eval(e)# x - 2.5, y - 2.8 This works just as well: s = '__import__(os).system(rm -rf /)' I don' think it would since the eval would call tuple which would return a tuple of characters which would not unpack into x,y so

Re: [Tutor] accessing list from a string

2008-11-26 Thread Kent Johnson
On Wed, Nov 26, 2008 at 2:46 PM, Alan Gauld [EMAIL PROTECTED] wrote: Kent Johnson [EMAIL PROTECTED] wrote e = tuple( + s + ) x,y = eval(e)# x - 2.5, y - 2.8 This works just as well: s = '__import__(os).system(rm -rf /)' I don' think it would since the eval would call tuple

Re: [Tutor] accessing list from a string

2008-11-26 Thread Alan Gauld
Kent Johnson [EMAIL PROTECTED] wrote This works just as well: s = '__import__(os).system(rm -rf /)' I don' think it would since the eval would call tuple which would return a tuple of characters which would not unpack into x,y so throwing an error. Care to try it? It does raise an

[Tutor] accessing list from a string

2008-11-25 Thread Bryan Fodness
I have a list in a text file that is in the python format., Positions = [2.5,2.8] and would like to grab the values. for line in file('list.txt'): if line == Positions: x1,x2=Positions I know this does not work. Is there a direct way to get my x1 and x2 values.

Re: [Tutor] accessing list from a string

2008-11-25 Thread Mark Tolonen
Bryan Fodness [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have a list in a text file that is in the python format., Positions = [2.5,2.8] and would like to grab the values. for line in file('list.txt'): if line == Positions: x1,x2=Positions I know

Re: [Tutor] accessing list from a string

2008-11-25 Thread A.T.Hofkamp
Bryan Fodness wrote: I have a list in a text file that is in the python format., Positions = [2.5,2.8] Why do you use Python format for storing data? (Python format is for storing programs, usually) and would like to grab the values. for line in file('list.txt'): if line

Re: [Tutor] accessing list from a string

2008-11-25 Thread Lie Ryan
On Tue, 25 Nov 2008 06:59:13 -0800, Mark Tolonen wrote: Bryan Fodness [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have a list in a text file that is in the python format., Positions = [2.5,2.8] and would like to grab the values. for line in file('list.txt'):

Re: [Tutor] accessing list from a string

2008-11-25 Thread Alan Gauld
Bryan Fodness [EMAIL PROTECTED] wrote I have a list in a text file that is in the python format., Positions = [2.5,2.8] When you say in the Python format do you mean it is real Python codfe or just that it happens to look like Python? If the latter what format is it really? If its a

Re: [Tutor] accessing list from a string

2008-11-25 Thread Kent Johnson
On Tue, Nov 25, 2008 at 3:14 PM, Lie Ryan [EMAIL PROTECTED] wrote: Instead, in python 2.6, you may use ast.literal_eval(). Which restrict the eval to literal syntax only, and prohibit any function calling. That's very cool, thanks! Alternatively, for previous versions of python, or for more

Re: [Tutor] accessing list from a string

2008-11-25 Thread John Fouhy
On 26/11/2008, Alan Gauld [EMAIL PROTECTED] wrote: You could use eval to evaluate the string but that would be dangerous since the striong could be a malicious piece of code. But you can make it a lot safer by wrapping it in a function with known effect, thus: s = [2.5,2.8] # your string