Reputation: 8173
In Matlab, at the beginning of every file, I usually write
clear; close all; clc
Is there something similar to this in Python? What do most people do when testing their scripts?
Upvotes: 13
Views: 45680
Reputation: 155
Use %reset -f
for clearing all the variables (without -f you have to confirm the clear command).
The equivalent command to MATLAB's clc
is %clear
in Spyder (for which you can use the shortcut "ctrl + L" as well).
Finally, plt.close('all')
works like close all
in MATLAB (you have to first import pyplot using the command import matplotlib.pyplot as plt
).
Upvotes: 1
Reputation: 29
I using either
print ("\n"*80)
Or
import os
clear = lambda: os.system('cls') # On Windows System
clear()
Upvotes: 0
Reputation: 390
The catch here is that plt.show() is blocking and will not return to the script until the window is closed manually. You can try plt.draw(), which is interactive and will allow the script to continue running after the figure has been drawn.
There is another question which discusses the difference between show and draw:
Difference between plt.show() and plt.draw()
Then the close should work.
Upvotes: 4