Python 使用字符填充对齐字符串

字符串方法"A".rjust(10) # 右侧加空格 "A".ljust(10,"-") # 右侧加横线 "A".center(10,"=") # 两端加等号 f-strings 语法右侧加字符 width = 15 padding = ' ' print(f'{"I am legend" :{padding}<{width}}') 左侧加字符

Shell 获取当前脚本文件路径

以下代码适用于 bash 和 zsh: # 此脚本文件的绝对路径 SCRIPT_FILE=$(readlink -f $0) # 此脚本文件所在文件夹的绝对路径 SCRIPT_DIR=$(dirname $SCRIPT_FILE) # 注意:这两行要分开写,不要合并成一句,否则变量内容为空

Python 使用 nacl 生成密钥对

import nacl.signing import nacl.public def generate_ed25519_keypair(): "return (public_key, private_key)" signing_key = nacl.signing.SigningKey.generate() pk = signing_key.verify_key._key sk = signing_key._signing_key return (pk, sk) def generate_curve25519_keypair(): "return (public_key, private_key)" sk = nacl.public.PrivateKey.generate() pk = sk.public_key return (pk, sk)

Install pip3 on Ubuntu

本文章引用自: https://www.educative.io/edpresso/installing-pip3-in-ubuntu ,版权归原作者所有。 pip3 is the official package installer for Python 3. It can be used to install packages from the Python Package Index. Installation Step 1 - Update systemIt is always a good idea to update before trying to install a new package. Run the command below: sudo apt update Step 2 - Install

pip 安装 Python 库到指定目录

可以使用 t (target) 选项来指定安装的位置。 举例: pip install -r requirements.txt -t /path/to/directory 安装到当前路径: pip install -r requirements.txt -t . 参考 https://pip.pypa.io/en/stable/reference/pip_install/#cmdoption-t

Python之禅

如何显示? import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face