Is there a way to restart or reset the python interpreter as part of the python doctrine?

I am writing a short tutorial and would like to be able to run examples in it using python doctest using

python -m doctest foo.txt

There is a point in the tutorial where I want to start using a new, clean python interpreter. Is there a mechanism for this?

+5
source share
1 answer

If you only want to run the new python interpreter inside the python interpreter, you can simply execute the command: 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']
>>>

reset python python, , . , .

Python Interpreter

0

All Articles