python:加载thrift类并运行交互式shell
在django框架中,您可以运行python:加载thrift类并运行交互式shell,python,console,thrift,python-interactive,Python,Console,Thrift,Python Interactive,在django框架中,您可以运行 ./manage.py shell 您将进入带有django设置的交互式shell。我可以使用 #!/usr/bin/env python import code code.interact(local=locals()) 我想和django做的一样——执行python脚本进入交互式shell(我的本地旧软件包已经导入了,这就是线索)。我不太清楚你所说的“我的本地旧软件包已经导入了”是什么意思,但是,如果您想使用全局名称空间中已经定义的特定符号集启动交互式
./manage.py shell
您将进入带有django设置的交互式shell。我可以使用
#!/usr/bin/env python
import code
code.interact(local=locals())
我想和django做的一样——执行python脚本进入交互式shell(我的本地旧软件包已经导入了,这就是线索)。我不太清楚你所说的“我的本地旧软件包已经导入了”是什么意思,但是,如果您想使用全局名称空间中已经定义的特定符号集启动交互式shell,我会在函数中执行,并导入其中的符号,以避免子shell被其他代码中任何不需要的符号污染 例如,如果您想启动一个已经导入了
sys
和os
的交互式shell,那么类似的东西应该可以工作
>>> import code
>>> def start_shell():
... import sys, os
... code.interact(local=locals())
...
>>> start_shell()
Python 2.7.4 (default, Apr 19 2013, 18:28:01)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> dir()
['__builtins__', 'os', 'sys']
…注意到已定义了sys
和os
,但未定义code
,因为它已导入全局命名空间,而不是本地命名空间