pep8

How to break a line in a function definition in Python according to pep8?

How to break a line in a function definition in Python according to pep8? Question: I have the following line of code that is just over the limit of 79 characters: def ReportResults(self, intTestID, startTime, stopTime, version, serverType): How do I break the line in the correct way according to pep8? Asked By: Michael || …

Total answers: 2

matplotlib.use required before other imports clashes with pep8. Ignore or fix?

matplotlib.use required before other imports clashes with pep8. Ignore or fix? Question: I have a Python script that starts like this: #!/usr/bin/env python import matplotlib matplotlib.use("Agg") from matplotlib.dates import strpdate2num import numpy as np import pylab as pl from cmath import rect, phase It works like a charm, but my editor complains: E402 module level …

Total answers: 3

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

PEP8 – import not at top of file with sys.path Question: 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 …

Total answers: 8

What does it means to not exceeding 80 characters in a line in Python?

What does it means to not exceeding 80 characters in a line in Python? Question: There is a mention that it is preferable for that a line in a Python script should not exceed more than 80 characters. For example: print(“A very long strings”) Does it include the characters of the print function, the strings …

Total answers: 4

How to disable special naming convention inspection of PEP 8 in PyCharm

How to disable special naming convention inspection of PEP 8 in PyCharm Question: I installed PyCharm and enabled pep8 checks in Inspections. If I write: def func(argOne): print(argOne) The IDE shows me this warning: Argument name should be lowercase There is no option to ignore only such inspection. I cant find such error number to …

Total answers: 4

python pep8 class in init imported but not used

python pep8 class in init imported but not used Question: I’m doing PEP8 checks in python using the python flake8 library. I have an import statement in an __init__.py file in one of my sub-modules which looks like this: from .my_class import MyClass The reason I have this line in the init file is so …

Total answers: 3

How to prevent "too broad exception" in this case?

How to prevent "too broad exception" in this case? Question: I have a list of functions that may fail and, if one fails, I don’t want the script to stop, but to continue with next function. I am executing it with something like this : list_of_functions = [f_a, f_b, f_c] for current_function in list_of_functions: try: …

Total answers: 8

Is it wrong to use the "==" operator when comparing to an empty list?

Is it wrong to use the "==" operator when comparing to an empty list? Question: PyCharm (4.0.6) complains when I do a comparison to an empty list using the == operator, but it doesn’t when I use the is operator: I guess this is something related to PEP 8, but the problem is that when …

Total answers: 2

Why does PyCharm use 120 Character Lines even though PEP8 Specifies 79?

Why does PyCharm use 120 Character Lines even though PEP8 Specifies 79? Question: PEP8 clearly specifies 79 characters, however, PyCharm defaults to 120 and gives me the warning “PEP8: line too long (… > 120 characters)”. Did previous versions of PEP8 use 120 and PyCharm not update its PEP8 checker? I couldn’t find any previous …

Total answers: 3

Verifying PEP8 in iPython notebook code

Verifying PEP8 in iPython notebook code Question: Is there an easy way to check that iPython notebook code, while it’s being written, is compliant with PEP8? Asked By: Seanny123 || Source Answers: Install the pep8 extension for ipython notebook using the following command : %install_ext https://raw.githubusercontent.com/SiggyF/notebooks/master/pep8_magic.py Refer the official docs for more info. After that …

Total answers: 7