Home  >  Q&A  >  body text

代码规范 - Python代码,你会严格遵守PEP8吗?

Python代码,你会严格遵守PEP8吗?比如代码一行不超过79个字符,如果正好是80个字符,你会为了遵守PEP8而对代码进行调整吗?

PHPzPHPz2741 days ago1704

reply all(27)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 13:07:05

    1. 4 character indent, follow
    2. The use of spaces should be basically followed
    3. There are 79 characters per line, which is not adhered to, and I feel uncomfortable with line breaks
    4. Line break, basically follow

    The rest basically depends on the pep8 checker...

    reply
    0
  • 迷茫

    迷茫2017-04-17 13:07:05

    Reference for Python code specifications in vim, please comment

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:07:05

    Write randomly, then autopep8

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:07:05

    No. python is too slow. I use perl

    reply
    0
  • 黄舟

    黄舟2017-04-17 13:07:05

    Follow most of them, 79 characters are basically not complied with.

    reply
    0
  • 阿神

    阿神2017-04-17 13:07:05

    PEP8 is a recommended standard. The purpose of the standard is to unify code formats and habits, thus reducing reading costs to the greatest extent.
    The principle I follow is that I can abide by it if I want to, and if others don't abide by it, I can't.
    To put it bluntly, it is to make the code more readable.
    So if I don’t comply with PEP8, will it be unreadable?
    The variable names are easy to understand, the core code is commented in detail, the functional modules come with test cases, the modules have a reasonable structure and appropriate relationships, and the documentation is detailed. I think all of them are more important than PEP8.
    Of course, it is better to follow PEP8, but how many masters just like to write code that is concise and simple. Once you get used to it, the readability will be much better. If you want to be serious about such code and do not follow PEP8, you are a python novice, then you can only Noh chuckled.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 13:07:05

    1, Automation tool https://pypi.python.org/pypi/...
    2, IDE pycharm will prompt you whether what you write complies with the pep8 specification

    reply
    0
  • Cancelreply