Ticket #3381: pythonstartup.diff

File pythonstartup.diff, 1.1 KB (added by deryck, 17 years ago)

Here is a patch that applies against trunk as of r6230. The patch on #3386 looked better to me, with some modifications to honor both $PYTHONSTARTUP and .pythonrc.py

  • django/core/management/commands/shell.py

     
     1import os
    12from django.core.management.base import NoArgsCommand
    23from optparse import make_option
    34
     
    4344                import rlcompleter
    4445                readline.set_completer(rlcompleter.Completer(imported_objects).complete)
    4546                readline.parse_and_bind("tab:complete")
     47
     48            # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
     49            # conventions and get $PYTHONSTARTUP first then import user.
     50            if not use_plain:
     51                pythonrc = os.environ.get("PYTHONSTARTUP")
     52                if pythonrc and os.path.isfile(pythonrc):
     53                    try:
     54                        execfile(pythonrc)
     55                    except NameError:
     56                        pass
     57                import user
    4658            code.interact(local=imported_objects)
Back to Top