我正在写一个简短的教程,并希望能够使用 python 的 doctest 运行其中的示例
python -m doctest foo.txt
在教程中有一点我想开始使用一个新的、干净的 python 解释器。有这样做的机制吗?
如果你只想在 python 解释器中启动一个新的 python 解释器,你可以发出命令: os.system('python')
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__']
>>> import os
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__', 'os']
>>> os.system('python')
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__']
>>> quit()
0
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__', 'os']
>>>
但是,如果您想重新启动或重置 python 解释器而不是像上面那样启动新的 python 解释器,您可以查看此解决方案。我还没有探索过它,但应该可以帮助您入门。