pep8

proper formatting of python multiline [ for in ] statement

proper formatting of python multiline [ for in ] statement Question: How should i format a long for in statement in python ? for param_one, param_two, param_three, param_four, param_five in get_params(some_stuff_here, and_another stuff): I have found that i can brake a for in statement only with a backslash : for param_one, param_two, param_three, param_four, param_five …

Total answers: 2

Define functions with too many arguments to abide by PEP8 standard

Define functions with too many arguments to abide by PEP8 standard Question: 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? Asked By: Sudip …

Total answers: 7

Python for-loop without index and item

Python for-loop without index and item Question: Is it possible in python to have a for-loop without index and item? I have something like the following: list_1 = [] for i in range(5): list_1.append(3) The code above works fine, but is not nice according to the pep8 coding guidelines. It says: “Unused variable ‘i’”. Is …

Total answers: 2

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

How come the Python's logging module doesn't follow PEP8 conventions? Question: 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 …

Total answers: 1

Import order coding standard

Import order coding standard Question: 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 …

Total answers: 6

Can not get past illogical line pep8 error

Can not get past illogical line pep8 error Question: I’ve been trying to fix this for a while now and I just can’t get it to pass pep8. Here is my code: 1. if (len(regex) > 2 and regex[0] == ‘(‘ and regex[-1] == ‘)’ and sum(regex.count(char) for char in splitter) == 1 and regex.count(‘(‘) …

Total answers: 3

What's the correct way to sort Python `import x` and `from x import y` statements?

What's the correct way to sort Python `import x` and `from x import y` statements? Question: The python style guide suggests to group imports like this: Imports should be grouped in the following order: standard library imports related third party imports local application/library specific imports However, it does not mention anything how the two different …

Total answers: 6

pep8 warning on regex string in Python, Eclipse

pep8 warning on regex string in Python, Eclipse Question: Why is pep8 complaining on the next string in the code? import re re.compile(“d{3}”) The warning I receive: ID:W1401 Anomalous backslash in string: ‘d’. String constant might be missing an r prefix. Can you explain what is the meaning of the message? What do I need …

Total answers: 2

How to disable a pep8 error in a specific file?

How to disable a pep8 error in a specific file? Question: 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 ? Asked By: Flows || Source Answers: As far as I know, you can’t. …

Total answers: 8

Does PEP 8 require whitespace around operators in function arguments?

Does PEP 8 require whitespace around operators in function arguments? Question: I have this code: some_list = range(a, b+1) After checking my coding style with pep8 plugin for vim, I got this warning: missing whitespace around operator It seems that to be compliant with PEP 8 I should instead write this? some_list = range(a, b …

Total answers: 3