宽客秀

宽客秀

Quant.Show的Web3站点,Archives from quant.show

Simple Operations Management Based on Python

  1. Environment Description

d2b5ca33bd970f64a6301fa75ae2eb22 1

  1. 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.

d2b5ca33bd970f64a6301fa75ae2eb22 2

You can also install pip first, and then install external libraries using pip (taking pandas as an example).

d2b5ca33bd970f64a6301fa75ae2eb22 3

  1. Editing and Executing Python Files Using Nano

Specify the execution directory of Python3 at the beginning of the file,

d2b5ca33bd970f64a6301fa75ae2eb22 5

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.

d2b5ca33bd970f64a6301fa75ae2eb22 6

  1. System Information Retrieval

Use the shutil package to check disk space

d2b5ca33bd970f64a6301fa75ae2eb22 8

Use the psutil package to check the health of the CPU

d2b5ca33bd970f64a6301fa75ae2eb22 9

  1. 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.

d2b5ca33bd970f64a6301fa75ae2eb22 12

d2b5ca33bd970f64a6301fa75ae2eb22 14

Use the "with" keyword to complete the open-read-close action in one step

d2b5ca33bd970f64a6301fa75ae2eb22 17

Sort all lines

d2b5ca33bd970f64a6301fa75ae2eb22 18

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.

d2b5ca33bd970f64a6301fa75ae2eb22

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.