When I run an interactive Python inside an Emacs shell buffer (M-x shell), it does two surprising things to the TTY. First, it turns on input echo, which persists after Python exits, until I do stty -echo. Secondly, it doesn't accept C-d (or C-q C-d, i.e. ^D) as EOF: I have to type quit() to leave the Python. How can I stop these two behaviours?

I know that I could run python-shell, but I don't want to: I'm noodling about in the shell and I want to do five lines of Python and then C-d out of it. So "run python-shell" is not an answer to my question.

Python running in a Terminal window is fine: ^D keeps working and echo doesn't change.

Python 2.7.5, GNU Emacs 24.3.1, OS X 10.8.5

Edited to add this snippet from a shell buffer:

```
bash-3.2$ echo foo 
foo                     # no echo.
bash-3.2$ cat
foo                     # I typed this.
foo                     # cat returned it; no additional echo.
bash-3.2$ python
Python 2.7.5 (default, May 19 2013, 13:26:46) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>                   # C-d has no effect. C-q C-d has no effect.
                      # not sure where this blank link has come from.
>>> quit()              # I have to type this to get out of Python
quit()                  # note that it is echoed, like anything I now type.
bash-3.2$ echo foo
echo foo                # now I am getting my input echoed.
foo
bash-3.2$ cat
cat                     # echo of the 'cat' command.
foo                     # my input
foo                     # echo of my input.
foo                     # cat's output.
bash-3.2$ stty -echo    # turn echo back off.
stty -echo
bash-3.2$ echo foo
foo                     # and it's off.
bash-3.2$ 

```