[Tutor] dangers of input()

Alan Gauld alan.gauld at blueyonder.co.uk
Tue Jul 20 23:57:59 CEST 2004


> I was thinking of using input() instead of raw_input in my Frac.py
> (posted yesterday). This would enable the user to enter things such
as
> "4**-3". Am I correct in assuming that this would be impossible to
do
> without using input()?

No, you could use eval() instead.
eval() has the advantage of allowing you to sanity check the string
before executing it.

input allows a user to type

import os; os.system('del *.*')


> If so, I may go ahead with input()--I'm the only  user, after all.

If you will always be the sole user input is fine, I use it all the
time for my own use, but be aware that own-use can often become
shared use...

Alan G.



More information about the Tutor mailing list