When using a loop in python, because the data is too large, the loop causes the running memory to accumulate, and finally the computer crashes. So, check it, how can it be like matlab in spyder
Clear a single variable (clear; clc).
1、 Commands in the code: delete a single variable, add and run in the code
del variable
2、 Delete all variables in Ipython console
reset
Once deleted, variables cannot be recovered.Proceed(y/[n])?
y
3、 Clear the command history of the console
clear
Content expansion:
Python delete all custom variable methods
When we create multiple variables in pythonwin, through the dir() function, we can see all the created variables. These created variables will be saved in the globals. If you want to delete them quickly, you can use the following script: Amitabha, haha.
1、 The script content is as follows:
# Delete clear_env.py
======================================
def __clear_env():for key inglobals().keys():if not key.startswith("__"): #Exclude system built-in functions
globals().pop(key)======================================
2、 Usage: Copy the script to d:/
import sys
sys.path.append(<import clear_env #import clear_env.py module
clear_env.__clear_env() #Execute the module function __clear_env() to clear custom variables
Okay, Nanwu Amitabha, it's done. If you find it troublesome, you can directly enter the following code on the python command line:
for key inglobals().keys():if not key.startswith("__"):globals().pop(key)
So far, this article on how to clear python variables is introduced. For more information about clearing python variables, please search for the previous articles of ZaLou.Cn or continue to browse the related articles below. Hope you will support ZaLou more in the future. Cn!
Recommended Posts