Using get_locals/get_globals instead of static references. This fixes a bug for ptipython.
Fixed input validation for ptipython: accept 'a=\!ls' as input.