[Tutor] Importing file data into Python arrays

Kirby Urner urnerk@qwest.net
Mon, 27 May 2002 14:53:13 -0700


You can also hand your strings to something like:

  def getdata(strdata):
    return [eval(i) for i in strdata.split()]

  >>> getdata('1.2  7e6 -1  10.39\n')
  [1.2, 7000000.0, -1, 10.390000000000001]

People like to warn against eval(), but if it's your
program written for you on your computer, go right
ahead.

So many of these anti-eval() arguments boil down to
reasoning like:  one shouldn't be allowed to use knives,
because one might cut one's own wrists (or throat)
with them.

That argument only makes sense if you presume a
self-destructive programmer (or a completely inept
one), in which case there a many more direct ways
to wreak havoc.

Kirby