034 Python代码写得丑怎么办?

一、Jupyter notebook 篇Jupyter notebook的代码要想写得规范,推荐用Code prettify插件。安装插件首先插件Nbextensions执行以下命令

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
pip install jupyter_contrib_nbextensions
````

<hr>

无报错再执行

<hr>

```python
jupyter contrib nbextension install --user

选取Code prettify模块 备注:需要安装 yapf模块

1
pip install yapf

安装完成后打开jupyter notebook 1 打开编辑 image.png 2 点开 nbxtensions config image.png 3 选中code pretlity 4 返回代码界面刷新一下就可以看到代码整理工具: image.png 是个小锤子,只要书写完代码点击一下就可以了. 比如一开始写的代码是这样的: image.png 整理完成后就会变成这样的 image.png 再也不怕写的代码丑了 代码不规范,同事两行泪,哈哈