pep8

How to disable a pep8 error in a specific file?

风格不统一 提交于 2019-11-30 06:35:10
问题 I tried with #:PEP8 -E223 or # pep8: disable=E223 I thought the second would work but doesn't seems to work. Do you have an idea how I can handle this ? 回答1: As far as I know, you can't. You can disable errors or warnings user wide, or per project. See the documentation. Instead, you can use the # noqa comment at the end of a line, to skip that particular line (see patch 136). Of course, that would skip all PEP8 errors. The main author argues against source file noise, so they suggested #

Wrapping python doctest results that are longer than 80 characters

自作多情 提交于 2019-11-30 05:39:35
I'm trying to keep my source code under the 80 character guideline width that PEP8 recommends, but can't figure out how to wrap my doctest which has results longer than 80 characters. A noddy example: def long_string(): """ Returns a string which is wider than the recommended PEP8 linewidth >>> print long_string() 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 """ return '0123456789' * 10 I've tried a couple of combinations, including using # doctest: +NORMALIZE_WHITESPACE and trying to simply wrap the line with a newline. Just figured out:

How come the Python's logging module doesn't follow PEP8 conventions?

杀马特。学长 韩版系。学妹 提交于 2019-11-30 01:24:13
This is is just a curiosity with historical purposes: I was wondering if someone knows why the very widely used (and core module) logging doesn't follow the Python's PEP-8 naming convention . For instance, in >>> import logging >>> log = logging.getLogger("hello") I would expect it to be get_logger , but it isn't. When it comes to function names , the PEP8 standard says: mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility. Was that the case? If so, with what other logging thingy it had to maintain backwards

Pycharm's code style inspection: ignore/switch off specific rules

别等时光非礼了梦想. 提交于 2019-11-30 00:09:26
问题 I'm trying to import existing project into PyCharm. I can refactor the code so that PyCharm will be pleased, but we like to have spaces around colons in dictionaries, like this: {"A" : "B"} . We also like aligning assignments: a = 1 abc = 3 Is there a way to configure PyCharm, so that he'll ignore all errors/warnings related to this specific stuff? 回答1: Using PyCharm 5 (community edition) , you can do the following: Code –> Inspect Code . Then select the required inspection error, and click

Is there a recommended format for multi-line imports?

我的未来我决定 提交于 2019-11-29 20:21:34
I have read there are three ways for coding multi-line imports in python With slashes: from Tkinter import Tk, Frame, Button, Entry, Canvas, Text, \ LEFT, DISABLED, NORMAL, RIDGE, END Duplicating senteces: from Tkinter import Tk, Frame, Button, Entry, Canvas, Text from Tkinter import LEFT, DISABLED, NORMAL, RIDGE, END With parenthesis: from Tkinter import (Tk, Frame, Button, Entry, Canvas, Text, LEFT, DISABLED, NORMAL, RIDGE, END) Is there a recomended format or a more elegant way for this statements? Personally I go with parentheses when importing more than one component and sort them

Should I use “camel case” or underscores in python? [duplicate]

99封情书 提交于 2019-11-29 20:08:44
This question already has an answer here: What is the naming convention in Python for variable and function names? 13 answers So which is better and why? def my_function(): or def myFunction(): aayoubi for everything related to Python's style guide: i'd recommend you read PEP8 . To answer your question: Function names should be lowercase, with words separated by underscores as necessary to improve readability. PEP 8 advises the first form for readability. You can find it here . Function names should be lowercase, with words separated by underscores as necessary to improve readability. Harish

PEP8 naming convention on test classes

╄→尐↘猪︶ㄣ 提交于 2019-11-29 17:08:39
问题 I have been looking at PEP 8 -- Style Guide for Python Code and PEP8 -- Advanced Usage for clues on how to name my test classes. However, this is never mentioned on both sites, as well as many other sites I have looked at, such as the unittest page in the Python documentation. The only consistent style I see is "CapWords". In the unittest documentation they have examples for TestSequenceFunctions as well as DefaultWidgetSizeTestCase. What I am trying to find out is whether to use "Name"Test

Comparison with boolean numpy arrays VS PEP8 E712

╄→гoц情女王★ 提交于 2019-11-29 14:05:33
PEP8 E712 requires that "comparison to True should be if cond is True: or if cond: ". But if I follow this PEP8 I get different/wrong results. Why? In [1]: from pylab import * In [2]: a = array([True, True, False]) In [3]: where(a == True) Out[3]: (array([0, 1]),) # correct results with PEP violation In [4]: where(a is True) Out[4]: (array([], dtype=int64),) # wrong results without PEP violation In [5]: where(a) Out[5]: (array([0, 1]),) # correct results without PEP violation, but not as clear as the first two imho. "Where what?" That advice only applies to if statements testing for the

Vim: How to indent to an open paren or bracket when hitting enter?

北城余情 提交于 2019-11-29 12:26:04
问题 I've been programming Python with Vim for a while but one thing I haven't been able to figure out how to do it set it to auto indent to the level of the last open paren. According to pep8 if you have an open paren and you need to break the line to fit in 80 columns then you're supposed to continue the next line at that open paren. Example: calling_some_really_long_function(that, has, way, too, many, arguments, to, fit, on, one, line) Obviously this is a crazy example, but that's how you're

Idiom for long tuple unpacking [closed]

我是研究僧i 提交于 2019-11-29 12:09:59
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . Scenario: you have a long tuple as a result of a SQL query and want to unpack it into individual values. What's the best way to do that while conforming to PEP8? So far I have these three options: single assignment, use backslash to split to multiple lines person_id, first