有没有办法在python doctest中重启或重置python解释器?

EHN*_*EHN 9 python doctest

我正在编写一个简短的教程,并希望能够使用python的doctest使用它来运行其中的示例

python -m doctest foo.txt

在教程中有一点我想开始使用一个新的,干净的python解释器.有没有这样做的机制?

Vij*_*jay -1

如果您只想在 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']
>>>
Run Code Online (Sandbox Code Playgroud)

但是,如果您想重新启动或重置 python 解释器,而不是像上面那样启动新的 python 解释器,您可以查看此解决方案。我还没有探索过,但应该可以帮助你开始。

安静地重新启动 Python 解释器