You can start an interactive console from inside a script with following code:

```
import code

# do something here

vars = globals()
vars.update(locals())
shell = code.InteractiveConsole(vars)
shell.interact()

```

When I run the script like so:

```
$ python my_script.py

```

an interactive console opens:

```
Python 2.7.2+ (default, Jul 20 2012, 22:12:53) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>

```

The console has all globals and locals loaded which is great since I can test stuff easily.

The problem here is that arrows don't work as they normally do when starting an Python console. They simply display escaped characters to the console:

```
>>> ^[[A^[[B^[[C^[[D

```

This means that I can't recall previous commands using the up/down arrow keys and I can't edit the lines with the left/right arrow keys either.

Does anyone know why is that and/or how to avoid that?