Pycharm配置autopep8实现流程解析

作者:-零 时间:2021-08-23 05:34:40 

关于PEP 8

PEP 8,Style Guide forPythonCode,是Python官方推出编码约定,主要是为了保证 Python 编码的风格一致,提高代码的可读性。

官网地址:https://www.python.org/dev/peps/pep-0008/

关于Autopep8

Autopep8是自动将Python代码格式化为符合PEP 8风格的工具。它使用pycodestyle工具来确定代码的哪些部分需要被格式化。Autopep8能够修复大部分pycodestyle检测的格式问题。

github地址:https://github.com/hhatto/autopep8

下载安装Autopep8

pip install autopep8

使用Autopep8

命令行使用方式如下

$ autopep8 --in-place --aggressive --aggressive <filename>
$ autopep8 --in-place --aggressive --aggressive Student.py

Pycharm配置Autopep8方法

1)具体流程:选择菜单「File」–>「Settings」–>「Tools」–>「External Tools」–>设置相关配置 -> 点击加号添加工具

填写如下配置项,点击「OK」保存

Settings–>Tools–>External Tools 点击添加按钮Name:autopep8(可以自定义)

Tools settings:

Programs:autopep8(不能修改)
Parameters:--in-place --aggressive --aggressive $FilePath$
Working directory:$ProjectFileDir$

Advanced Options:在output filters添加:$FILE_PATH$\:$LINE$\:$COLUMN$\:.*

3) 使用autopep8自动格式化你的python代码


import math

def example1():
 some_tuple = (1, 2, 3, 'a')
 some_variable = {
   'long': 'Long code lines should be wrapped within 79 characters.',
   'other': [math.pi, 100, 200, 300, 9876543210,'This is a long string that goes on'],
   'more': { 'inner': 'This whole logical line should be wrapped.',some_tuple: [ 1,20, 300, 40000,500000000,60000000000000000]}}
 return (some_tuple, some_variable)

def example2(): return ('' in {'f': 2}) in {'has_key() is deprecated': True};

class Example3(object):
 def __init__(self, bar):
   # Comments should have a space after the hash.
   if bar:
     bar += 1
     bar = bar * bar
   else:
     some_string = """
           Indentation in multiline strings should not be touched.Only actual code should be reindented.
"""

第一种方式:

编写完代码后,右键选择「Extern Tools」–>「autopep8」

Pycharm配置autopep8实现流程解析

第二种方式:

选择菜单「Tool」–>「Extern Tools」–>「autopep8」即可

Pycharm配置autopep8实现流程解析

来源:https://www.cnblogs.com/-wenli/p/13491121.html

标签:Py,charm,配置,autopep8
0
投稿

猜你喜欢

  • 重新发现HTML表格

    2009-12-02 09:47:00
  • Python列表删除重复元素与图像相似度判断及删除实例代码

    2021-02-21 05:28:58
  • Python利用pygame模块制作代码雨

    2021-02-13 02:53:24
  • ASP中利用ADODB.Stream对象将字节流转换为字符流

    2008-06-07 08:56:00
  • 静态页面利用JS读取cookies记住用户信息

    2011-04-14 11:17:00
  • php cookie中点号(句号)自动转为下划线问题

    2023-09-07 11:05:04
  • 如何处理Python3.4 使用pymssql 乱码问题

    2021-07-02 12:01:11
  • Dreamweaver2004 中文乱码解决方案

    2007-01-31 10:20:00
  • SQL提高查询效率之Like篇

    2011-10-01 09:36:42
  • AJAX无刷新验证用户名是否存在

    2007-08-10 10:07:00
  • python七夕浪漫表白源码

    2021-09-27 23:22:13
  • CSS绝对定位在宽屏分辨率下错位

    2009-07-28 12:24:00
  • 使用Python和xlwt向Excel文件中写入中文的实例

    2023-08-27 19:18:08
  • 使用批处理实现mysql的数据库备份与上传

    2012-01-05 19:30:23
  • PHP 进程锁定问题分析研究

    2023-11-21 18:14:10
  • python实现自动化上线脚本的示例

    2021-02-01 05:14:49
  • Django DRF认证组件流程实现原理详解

    2021-01-03 08:48:49
  • Python JSON编解码方式原理详解

    2023-10-24 10:33:33
  • 五种方法解决 Web2.0设计中的匹配度

    2007-09-22 10:58:00
  • Python tkinter三种布局实例详解

    2022-11-28 11:23:44
  • asp之家 网络编程 m.aspxhome.com