- Environment Description
- Installing Python Libraries
Taking the PIL library as an example, if you encounter an error "Unable to locate package python3-pil" when installing python3-pil for the first time, execute "sudo apt update" first, and then install python3-pil.
You can also install pip first, and then install external libraries using pip (taking pandas as an example).
- Editing and Executing Python Files Using Nano
Specify the execution directory of Python3 at the beginning of the file,
Then use the chmod command to ensure that the file has executable permissions, and execute it directly, which is equivalent to python3 hello_world.py.
- System Information Retrieval
Use the shutil package to check disk space
Use the psutil package to check the health of the CPU
- File Read and Write
First, use open() to open the file, and then use readline() to read the file content line by line or use read() to read all the content after the current line. Finally, remember to use close() to close the file.
Use the "with" keyword to complete the open-read-close action in one step
Sort all lines
Write to a file using the "w" mode, create the file if it doesn't exist. In addition to "w" (overwrite write), there are also "r" (read only) mode, "a" (append) mode, and "r+" (read+write) mode. "30" is the return value, indicating successful writing and completing the writing of 30 characters.