pep8

What is the naming convention for Python class references

独自空忆成欢 提交于 2019-12-03 01:10:43
What is the naming convention for a variable referencing a class in Python? class MyClass(object): pass # which one is correct? reference_to_class = MyClass # or ReferenceToClass = MyClass Here is another example that resembles my situation: # cars.py class Car(object): pass class Sedan(Car): pass class Coupe(Car): pass class StatonWagon(Car): pass class Van(Car): pass def get_car_class(slug, config): return config.get(slug) # config.py CONFIG = { 'ford-mustang': Coupe, 'buick-riviera': Coupe, 'chevrolet-caprice': Sedan, 'chevy-wan' Van: 'ford-econoline': Van } # main.py from config.py import

Import order coding standard

半城伤御伤魂 提交于 2019-12-03 00:20:42
问题 PEP8 suggests that: Imports should be grouped in the following order: standard library imports related third party imports local application/library specific imports You should put a blank line between each group of imports. Is there a way to check if the standard is violated anywhere in the package using static code analysis tools, like pylint , pyflakes , pychecker , pep8 ? Example of violation: from my_package import my_module from django.db import models import os Correct way to import:

Python PEP8: Blank lines convention

白昼怎懂夜的黑 提交于 2019-12-02 21:52:35
I am interested in knowing what is the Python convention for newlines between the program parts? For example, consider this: import os def func1(): def func2(): What should be the ideal newline separation between: The import modules and the functions? The functions themselves? I have read PEP8 , but I wanted to confirm the above two points. Bryan Oakley Two blank lines between the import statements and other code. Two blank lines between each function. If one will check with 'Blank Lines' section of PEP8 — one will find the following: Surround top-level function and class definitions with two

Line is too long. Django PEP8

冷暖自知 提交于 2019-12-02 20:21:36
PEP8 info: models.py:10:80: E501 line too long (83 > 79 characters) Models.py: field = TreeForeignKey('self', null=True, blank=True, related_name='abcdefgh') How to correctly write this line? It's "correct", PEP8 just flags lines over 79 characters long. But if you're concerned about that, you could write it like this: field = TreeForeignKey('self', null=True, blank=True, related_name='abcdefgh') Or this: field = TreeForeignKey( 'self', null=True, blank=True, related_name='abcdefgh', ) Or, really, any other style that would break the single line into multiple shorter lines. I just found this

Visual studio code suppress pep8 warnings

落爺英雄遲暮 提交于 2019-12-02 20:11:56
How can I suppress pep8 warnings, in Visual studio code? What I want to do is to suppress E501 warning I don't want to get warnings where my code length is more than 80 chars. I'm using Don Jayamanne's Python extension and here is my config file for vscode { "python.linting.pylintEnabled": false, "python.linting.pep8Enabled": true, "python.pythonPath": "/workspace/virtualenvs/abr/bin/python3", "python.linting.enabled": true } I know that there is one another option "python.linting.pep8Args": [] but I couldn't to get it work. I've installed pep8 on virtualenv What I've already tried. "python

Define functions with too many arguments to abide by PEP8 standard

你离开我真会死。 提交于 2019-12-02 18:58:46
I have defined a function with a long list of arguments. The total characters in definition is above 80 and doesn't abide by PEP8. def my_function(argument_one, argument_two, argument_three, argument_four, argument_five): What can be the best approach to avoid horizontal scrolling. An example is given in PEP 8: class Rectangle(Blob): def __init__(self, width, height, color='black', emphasis=None, highlight=0): So that is the official answer. Personally I detest this approach, in which continuation lines have leading whitespace that doesn't correspond to any real indentation level. My approach

What PEP 8 guidelines do you ignore, and which ones do you stick to? [closed]

核能气质少年 提交于 2019-12-02 17:53:15
Over the years, the more Python I write, the more I find myself agreeing with most of the guidelines, though I consistently and intentionally break some for my own reasons. I'd be curious to know what in PEP 8 (or other PEPs too maybe) people religiously stick to and why, and what people find inconvenient or inadequate. In my case (and at work in general), there's only a handful of things we deviate from: Underscore separated lowercase names, I can see the point of it, as it will unfailingly be consistent, but we tend to use lowerCamelCase, even if it will occasionally introduce some

PEP8 – import not at top of file with sys.path

眉间皱痕 提交于 2019-12-02 16:30:01
Problem PEP8 has a rule about putting imports at the top of a file: Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants. However, in certain cases, I might want to do something like: import sys sys.path.insert("..", 0) import my_module In this case, the pep8 command line utility flags my code: E402 module level import not at top of file What is the best way to achieve PEP8 compliance with sys.path modifications? Why I have this code because I'm following the project structure given in The Hitchhiker's Guide to

Import order coding standard

廉价感情. 提交于 2019-12-02 15:45:44
PEP8 suggests that: Imports should be grouped in the following order: standard library imports related third party imports local application/library specific imports You should put a blank line between each group of imports. Is there a way to check if the standard is violated anywhere in the package using static code analysis tools, like pylint , pyflakes , pychecker , pep8 ? Example of violation: from my_package import my_module from django.db import models import os Correct way to import: import os from django.db import models from my_package import my_module The current version of pylint

PEP 8, why no spaces around '=' in keyword argument or a default parameter value?

北战南征 提交于 2019-12-02 15:41:29
Why does PEP 8 recommend not having spaces around = in a keyword argument or a default parameter value ? Is this inconsistent with recommending spaces around every other occurrence of = in Python code? How is: func(1, 2, very_long_variable_name=another_very_long_variable_name) better than: func(1, 2, very_long_variable_name = another_very_long_variable_name) Any links to discussion/explanation by Python's BDFL will be appreciated. Mind, this question is more about kwargs than default values, i just used the phrasing from PEP 8. I'm not soliciting opinions. I'm asking for reasons behind this