python常见问题

项目常用

生成requirements.txt

使用pipreqs生成requirements

1
2
3
4
# 安装
pip install pipreqs
# 在当前目录生成(若存在即覆盖)
pipreqs . --encoding=utf8 --force

使用requirement.txt安装依赖:

1
pip install -r requirements.txt

pythonic的编码方式

变量的交换

1
a, b = b, a

利用百分号语法进行字符串格式化

1
2
3
4
5
a = 'Curry'
b = 'Player'
print("%s is the best %s" % (a,b))
#################
Curry is the best Player

将两个字典合并(解包操作)

1
2
3
a = {}
b = {}
c = {**a, **b} # 解包
Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2019-2021 子夜
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信