diff --git a/wcs/ctl/shell.py b/wcs/ctl/shell.py index adf525c3f..1df31e3df 100644 --- a/wcs/ctl/shell.py +++ b/wcs/ctl/shell.py @@ -69,16 +69,16 @@ class CmdShell(Command): readline.parse_and_bind("tab:complete") # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system - # conventions and get $PYTHONSTARTUP first then import user. + # conventions and get $PYTHONSTARTUP first then .pythonrc.py. if not sub_options.plain: - pythonrc = os.environ.get("PYTHONSTARTUP") - if pythonrc and os.path.isfile(pythonrc): - try: - execfile(pythonrc) - except NameError: - pass - # This will import .pythonrc.py as a side-effect - import user + for pythonrc in (os.environ.get("PYTHONSTARTUP"), + os.path.expanduser('~/.pythonrc.py')): + if pythonrc and os.path.isfile(pythonrc): + try: + with open(pythonrc) as handle: + exec(compile(handle.read(), pythonrc, 'exec')) + except NameError: + pass code.interact(local=imported_objects) shells = [ 'ipython', 'bpython' ]