I would like to check if an input is code before joining it to a larger variable to eventually execute, is there any way I can do this? For example:
import readline
while True:
codelines=[]
code=raw_input(">>> ")
if code.iscode():
codelines.append(code)
elif x=="end":
break
else:
print "Not usable code."
fullcode="\n".join(codelines)
try:
exec fullcode
except Exception, e:
print e
But I know of no command that works like .iscode()
importfrom any entered text. To avoid things like this__import__('os').system('rm -rf /')from being run.