autopep8怎么利用Pycharm进行配置-创新互联

autopep8怎么利用Pycharm进行配置?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

企业建站必须是能够以充分展现企业形象为主要目的,是企业文化与产品对外扩展宣传的重要窗口,一个合格的网站不仅仅能为公司带来巨大的互联网上的收集和信息发布平台,成都创新互联面向各种领域:成都塑料袋成都网站设计成都全网营销解决方案、网站设计等建站排名服务。

关于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
$ 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」

autopep8怎么利用Pycharm进行配置

第二种方式:

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

autopep8怎么利用Pycharm进行配置

看完上述内容,你们掌握autopep8怎么利用Pycharm进行配置的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


标题名称:autopep8怎么利用Pycharm进行配置-创新互联
标题网址:http://pwwzsj.com/article/dgioho.html