How do you undo x = `a` if A is a list?

Moshe Zadka moshez at
Fri Feb 11 16:14:34 EST 2000

On Fri, 11 Feb 2000, Trent Mick wrote:

> > Now how do I read that line in from a file and convert it from a
> > string to a
> > list?
> Here is one way. Save your variable in the proper format to a Python module.
> Don't know if I would recommend it. As Skip et al. suggest, eval() and its
> kin are probably better.

One reason to do what you suggest is to use a pre-calculated table.

for example

def primes(n):
	# generate a list of all primes less then n

a = primes(10000)
f = open("", 'w')


Then do "import primes" whenever you want a list of the primes less then
10000. It is *extremely* fast after the first time: it uses Python's
"marshal", which is heavily optimized.

Moshe Zadka <mzadka at>. 
INTERNET: Learn what you know.
Share what you don't.

More information about the Python-list mailing list