`
san_yun
  • 浏览: 2595121 次
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

python shell 交互模式

 
阅读更多

python 通过code模块可以很容易的进入交互模式:

import code
imported_objects = {}
code.interact(local=imported_objects)

 

django的shell模块:

imported_objects = {}
try: # Try activating rlcompleter, because it's handy.
    import readline
except ImportError:
    pass
else:
    # We don't have to wrap the following import in a 'try', because
    # we already know 'readline' was imported successfully.
    import rlcompleter
    readline.set_completer(rlcompleter.Completer(imported_objects).complete)
    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.
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
code.interact(local=imported_objects)

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics