How to clear variables in python

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

How to clear variables in python
How to understand variables in Python
How to understand global variables in Python
How to wrap in python code
How to omit parentheses in Python
How to write classes in python
How to read Excel in Python
How to view errors in python
How to write return in python
How to use SQLite in Python
How to use and and or in Python
How to delete cache files in python
How to introduce third-party modules in Python
How to represent null values in python
How to save text files in python
How to write win programs in python
How to run id function in python
How to install third-party modules in Python
How to custom catch errors in python
How to write try statement in python
How to define private attributes in Python
How to add custom modules in Python
How to view installed modules in python
How to open python in different systems
How to sort a dictionary in python
How to add background music in python
How to represent relative path in python
How to use the round function in python
How to use the zip function in Python
How to program based on interfaces in Python
How to install python in ubuntu server environment
How to simulate gravity in a Python game
How to use the format function in python
How to use code running assistant in python
How to set code auto prompt in python
Teach you how to write games in python
How to delete files and directories in python
How to write a confession program in python
How to perform continuous multiplication calculation in python
How to comment python code
How to learn python quickly
How to uninstall python plugin
How to understand python objects
How to use python tuples
How to understand the introduction of packages in Python
How to understand a list of numbers in python
Example of how to automatically download pictures in python
How to save IE as an attachment in python
How to create a Python virtual environment in Ubuntu 14.04
How to install Helm in Ubuntu
python how to view webpage code
How to use python thread pool
How to write python configuration file
How to find the area of a circle in python
How to install PHP7.4 in CentOS
How to install mysql in Ubuntu 14.04
How to install Python 3.8 on CentOS 8
How to install Python 3.8 on Ubuntu 18.04
How to install HDP2.6 in Centos7.2
How to solve python dict garbled
How to install mysql in Ubuntu 14.04