[Numpy-discussion] eval shortcomings?

A. M. Archibald peridot.faceted at gmail.com
Sun Sep 24 23:40:32 CDT 2006

On 25/09/06, Angus McMorland <amcmorl at gmail.com> wrote:
> Hi all,
> Can someone explain why the following occurs?
> a = numpy.zeros((100))
> b = numpy.ones((10))
> a[20:30] = b                    # okay
> eval('a[50:60] = b')         # raises SyntaxError: invalid syntax
> Is there some line mangling that the interpretor does that eval doesn't do?

No. Eval evaluates expressions, that is, formulas producing a value.
"a=b" does not produce a value, so you are obtaining the same error
you would if you'd written

if a=b:

The way you run code that doesn't return a value is with "exec".

A. M. Archibald

More information about the Numpy-discussion mailing list