Home  >  Q&A  >  body text

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

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

PHPzPHPz2741 days ago1705

reply all(27)I'll reply

  • 巴扎黑

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

    Personally, I think following certain rules will make people who look at your code more comfortable.

    If you use vim, it is recommended that you use this plug-in.

    reply
    0
  • 巴扎黑

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

    Not necessarily. For example, pep does not recommend using *args **kwargs in methods. However, for the sake of code flexibility, I will consider not complying with pep8

    reply
    0
  • 阿神

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

    pycharm will prompt you with obsessive-compulsive disorder

    reply
    0
  • PHP中文网

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

    Use autopep8 to automatically format the code. Except for the 80 characters per line, I will abide by everything else, otherwise the code will look very awkward

    reply
    0
  • 黄舟

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

    Yes. If you use 80, you can open two windows in vim, and it is easier to write doc. I will abide by it, but don’t do it deliberately. For example, I am used to using single quotes to write docstring comments ' instead of double quotes ".

    reply
    0
  • PHP中文网

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

    I didn’t think it had to be like this. Once the IDE is set up, I don’t have to worry about it

    reply
    0
  • 黄舟

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

    I know how to do it...The code I write will look good...and I want to upload it to github..Although no one will read it, I will always be afraid that someone will make noise...

    reply
    0
  • PHP中文网

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

    Must comply

    reply
    0
  • PHPz

    PHPz2017-04-17 13:07:05

    Complies with PEP8, which is more conducive to building a standard and readable code
    In fact, I think PEP8 itself is still a very loose standard

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 13:07:05

    The length is set to 120, pep8 check is enabled by default

    reply
    0
  • Cancelreply