[Tutor] putting together commands
Magnus Lycka
magnus@thinkware.se
Wed, 16 Oct 2002 21:11:30 +0200
At 17:00 2002-10-16 +0000, Terje Johan Abrahamsen wrote:
>But, as I expected, q is a string. I cannot run a string. How do I come=20
>around this problem? Any suggestions?
Sean is right here. You shouldn't try to run a string
*in this case*. There are times when you want that though,
and it's easy:
>>> a =3D "print 'Hello '*5"
>>> exec(a)
Hello Hello Hello Hello Hello
You can also evaluate expressions:
>>> e =3D "4*5**3"
>>> r =3D eval(e)
>>> print r
500
--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se