Search code examples
pythonraw-input

Python: Making raw_input execute


I'm fairly new to Python (I'm using Codecademy and am about 70% through,) and I'm wondering if it's possible for raw_input to run as an actual command. For instance, I thought I could use:

command = raw_input(">>>    ")
command

However, when I run it, it displays the >>> and allows me to type stuff, but the code I type won't run.

Is there a way to do this?


Solution

  • You can use:

    command = raw_input(">>>    ")
    exec(command)
    

    but beware the user can execute anything!