View All Posts. MiCHiLU.com powered by Django ;-)

[Django]: manage.py shellでclassic promptのIPythonを使えるようにする

パッチはあまり好きじゃないのだけれど、便利そうだからいいや。 via IPythonを使おう1 @ueblog

$ svn diff
Index: django/core/management/commands/shell.py
===================================================================
--- django/core/management/commands/shell.py    (revision 6285)
+++ django/core/management/commands/shell.py    (working copy)
@@ -6,6 +6,8 @@
     option_list = NoArgsCommand.option_list + (
         make_option('--plain', action='store_true', dest='plain',
             help='Tells Django to use plain Python, not IPython.'),
+        make_option('--cl', action='store_true', dest='cl',
+            help='Tells Django to use IPython with the classic Python prompt.'),
     )
     help = "Runs a Python interactive interpreter. Tries to use IPython, if it's available."

@@ -18,6 +20,9 @@
         loaded_models = get_models()

         use_plain = options.get('plain', False)
+        argv = []
+        if options.get('cl', False):
+            argv.append("-cl")

         try:
             if use_plain:
@@ -26,7 +31,7 @@
             import IPython
             # Explicitly pass an empty list as arguments, because otherwise IPython
             # would use sys.argv from this script.
-            shell = IPython.Shell.IPShell(argv=[])
+            shell = IPython.Shell.IPShell(argv)
             shell.mainloop()
         except ImportError:
             import code
$ ./manage.py shell --cl
Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
Type "copyright", "credits" or "license" for more information.

IPython 0.8.1 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
>>> import django
>>> django.VERSION??
Type:           tuple
Base Class:     <type 'tuple'>
String Form:    (0, 97, 'pre')
Namespace:      Interactive
Length:         3
Docstring [source file open failed]:
    tuple() -> an empty tuple
    tuple(sequence) -> tuple initialized from sequence's items

    If the argument is a tuple, the return value is the same object.

>>>
Fri, 21 Sep 2007 16:44:41 +0900 source edit
Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.1 Japan License.
View All Posts. MiCHiLU.com powered by Django ;-)