pep8

Using pass on a non necessary else statement

半腔热情 提交于 2019-11-29 07:29:52
Based on PEP8 documentation, I was not able to find any reference regarding if I should use pass for aesthetic reasons on code. Based on the example below, should I keep those else or can I erase them? Until now, the main reason I'm keeping it is based on the mantra "Explicit is better than implicit." if fields: for i in foo: if i == 'something': print "something" else: pass else: pass Yes, you can/should remove them because they do nothing. The Python community teaches "explicit is better than implicit" as long as the explicit code does something useful. Those else: pass 's however contribute

Wrapping python doctest results that are longer than 80 characters

不问归期 提交于 2019-11-29 06:00:34
问题 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

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

谁都会走 提交于 2019-11-28 22:14:03
问题 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

How to disable a pep8 error in a specific file?

こ雲淡風輕ζ 提交于 2019-11-28 21:00:23
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 ? 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 # pep8 comments don't get included. Note that there is also nopep8 , which is the equivalent. noqa (which

How to configure PyLint to check all things PEP8 checks?

痴心易碎 提交于 2019-11-28 20:14:13
Searching for an answer on PyLint's mailing list brings no interesting results. PyLint is known to be very customizable so I guess this should be possible... The reason I would like PyLint to check compliance with PEP8 is because PyDev has much better support for PyLint than it has for PEP8. It's easier to have one tool doing all checks than having to use two. I also asked this question on PyLint's mailing list at http://thread.gmane.org/gmane.comp.python.logilab/1039 Example of diagnostic messages from PEP8 which I don't get from PyLint: E203 whitespace before ':' E225 missing whitespace

What does '# noqa' mean in Python comments?

天大地大妈咪最大 提交于 2019-11-28 18:04:36
While searching through a Python project, I found a few lines commented with # noqa . import sys sys.path.append(r'C:\dev') import some_module # noqa What does noqa mean in Python? Is it specific to Python only? jimf Adding # noqa to a line indicates that the linter (a program that automatically checks code quality) should not check this line. Any warnings that code may have generated will be ignored. That line may have something that "looks bad" to the linter, but the developer understands and intends it to be there for some reason. For more information, see the Flake8 documentation for

How can I make my Python code stay under 80 characters a line? [closed]

三世轮回 提交于 2019-11-28 15:57:14
问题 I have written some Python in which some lines exceed 80 characters in length, which is a threshold I need to stay under. How can I adapt my code to reduce line lengths? 回答1: My current editor (Kate) has been configured to introduce a line break on word boundaries whenever the line length reaches or exceeds 80 characters. This makes it immediately obvious that I've overstepped the bounds. In addition, there is a red line marking the 80 character position, giving me advance warning of when the

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

别来无恙 提交于 2019-11-28 14:46:18
问题 This question already has answers here : What is the naming convention in Python for variable and function names? (13 answers) Closed 5 years ago . So which is better and why? def my_function(): or def myFunction(): 回答1: 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. 回答2: PEP 8 advises the first form for readability. You can find

Enable pep8 in Eclipse

让人想犯罪 __ 提交于 2019-11-28 13:57:20
I enabled PEP8 in my Eclipse Luna for a pydev project and it works if I create a new file but it doesn't work for an existing project/file. I enabled PEP8 in window> preferences > pydev > editor > codeAnalysis > pep8.py > warning and I tried to click right onto my project folder > pydev > code analysis But unfortunately it doesn't work. PyDev will only analyze valid packages in the PYTHONPATH (i.e.: under a source folder). So, Are your sources in the existing project under a source folder and are folders actually packages (i.e.: do they have __init__.py files?) See: http://pydev.org/manual_101

How to choose proper variable names for long names in python

佐手、 提交于 2019-11-28 11:19:15
I need help choosing proper names for variables with long actual names. I have read pep8 docs, but I couln't find addressed such issue. Would you rename very_long_variable_name to something like vry_lng_var_nm or would you leave it as it is. I notice that pythons build in libraries have very short names and I'd like to follow the conventions if it exists for this case. I know I can name it something not very descriptive and add description, which would explain its meaning, but what do you think should be the variables name. PEP8 recommends short variable names, but achieving this requires good