From 723c9a8c6db60108f584972498fa6bbd3b408444 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Wed, 29 Aug 2012 23:43:10 +0200 Subject: [PATCH] [py3] Ported the 'shell' management command. The user module and the execfile function were removed in Python 3. Thanks Linovia for the report. --- django/core/management/commands/shell.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/django/core/management/commands/shell.py b/django/core/management/commands/shell.py index 4e7d1dbbf4..52a8cab7e4 100644 --- a/django/core/management/commands/shell.py +++ b/django/core/management/commands/shell.py @@ -80,14 +80,14 @@ class Command(NoArgsCommand): 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 use_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)