eval()
Cliff Wells
logiplexsoftware at earthlink.net
Wed Mar 20 15:43:29 EST 2002
On Wed, 20 Mar 2002 20:31:46 -0000
maximilianscherr wrote:
> what does eval exactly do?
>
> could it do somehting like opening a text file with this:
>
> hello = 1
> if hello = 1:
> print 'yeah'
>
> eval(readline()[:-1])
> ...
You would want exec for that. eval is for evaluating an expression, not a
statement:
Python 2.2 (#1, Mar 15 2002, 11:52:42)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = eval("1 + 2")
>>> a
3
>>> exec "a = 2 + 3"
>>> a
5
>>>
--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308 (800) 735-0555 x308
More information about the Python-list
mailing list