[Tutor] The Evil eval()

Blake Winton bwinton@tor.dhs.org
Fri, 12 Apr 2002 10:47:33 -0400


* Timothy M. Brauch <tbrauch@tbrauch.com> [020412 01:38]:
> I am getting ready to write a program that will read the contents of a file
> and then manipulate the data.  The file consists of a single list of lists
> all on  one line.  Something like:
> 
> [[1, 2, 3, 4, 5], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15], [4, 8, 12, 16, 20]]
> 
> If I understand correctly, when I read the file in, I will get a string and
> to make it into a list of lists, I will have to use eval().  But, I also
> know that is dangerous and if someone knew I used that for this program,
> they could really mess things up.  My question is, how do I make sure that
> what I am eval()-ing is a list of lists (of integers)?  That is the only
> thing the input file should be, and I don't want it to work if there is
> something else inthe input file.

Or you could search the archives for "Turning a string into a
tuple" and find the thread that starts at:
http://mail.python.org/pipermail/tutor/2001-September/008963.html

Or just skip down and hit my code at:
http://mail.python.org/pipermail/tutor/2001-September/008992.html

That should do exactly what you want, and maybe even a little
more...  If there's anything else you need from it, let me
know, and I'll see what I can do.

Later,
Blake.
-- 
9:40pm up 52 days, 21:07, 2 users, load average: 0.02, 0.09, 0.07