pep8

Coding style (PEP8) - Module level “dunders”

烂漫一生 提交于 2019-12-08 14:39:52
问题 Definition of "Dunder" ( D ouble under score): http://www.urbandictionary.com/define.php?term=Dunder I have a question according the placement of module level "dunders" (like __all__ , __version__ , __author__ etc.) in Python code. The question came up to me while reading through PEP8 and seeing this Stack Overflow question. The accepted answer says: __author__ is a global "variable" and should therefore appear below the imports. But in the PEP8 section Module level dunder names I read the

Add path to sys.path vs. PEP E402

不问归期 提交于 2019-12-07 16:19:54
问题 In order to import a project specific module somewhere located on your disk, one can easily append this directory to sys.path: import sys sys.path.append(some_module_path) import some_module However, the latter import now violates PEP E402 ("module level import not at top of file"). At least spyder tells me so. Is spyder here too picky? In spyder there is the principal idea of a "project", where I assumed environments can be adjusted specific for this project. However, I have no clue, how to

Multiple right margins in Pycharm

风流意气都作罢 提交于 2019-12-06 19:16:25
问题 I am learning Pycharm Community Edition 3.4 and I was wondering If it was possible to have a right a margin for comments and docstring only, additionally to the regular margin for the rest of the code. I ask because I am trying to stick to the PEP8 guideline of 72 characters per comment and 79 for regular code. I am constantly changing the right margin between 72/79 to make sure everything is fine but I don't find that very efficient. Thanks in advance. 回答1: This feature was announced in

Store Python PEP8 module output

时间秒杀一切 提交于 2019-12-06 15:45:47
问题 I am using PEP8 module of python inside my code. import pep8 pep8_checker = pep8.StyleGuide(format='pylint') pep8_checker.check_files(paths=['./test.py']) r = pep8_checker.check_files(paths=['./test.py']) This is the output: ./test.py:6: [E265] block comment should start with '# ' ./test.py:23: [E265] block comment should start with '# ' ./test.py:24: [E302] expected 2 blank lines, found 1 ./test.py:30: [W293] blank line contains whitespace ./test.py:35: [E501] line too long (116 > 79

Add path to sys.path vs. PEP E402

谁说我不能喝 提交于 2019-12-06 02:44:23
In order to import a project specific module somewhere located on your disk, one can easily append this directory to sys.path: import sys sys.path.append(some_module_path) import some_module However, the latter import now violates PEP E402 ("module level import not at top of file"). At least spyder tells me so. Is spyder here too picky? In spyder there is the principal idea of a "project", where I assumed environments can be adjusted specific for this project. However, I have no clue, how to modify e.g. the sys.path depending on a spyder project. How can I modify sys.path in a spyder project?

Can't get past illogical line pep8 error

南楼画角 提交于 2019-12-05 20:32:20
问题 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('(') == 1 and regex.count(')') == 1): print('hi') 2. if (len(regex) > 2 and regex[0] == '(' and regex[-1] == ')' and sum(regex.count(char) for char in splitter) == 1 and regex.count('(') == 1 and regex.count(')') == 1): print('hi') 3. if (len(regex) > 2 and regex[0

Pep8 E501: line too long error

被刻印的时光 ゝ 提交于 2019-12-05 15:48:59
问题 I get the error E501: line too long from this code: header, response = client.request('https://api.twitter.com/1.1/statuses /user_timeline.json?include_entities=true&screen_name='+username+'&count=1') but if I write this way or another way: header, response = client.request('\ https://api.twitter.com/1.1/statuses/user_timeline.\ json?include_entities=true&screen_name='+username+'&count=1') I get this error: ValueError: Unsupported URL https://api.twitter.com/1.1/statuses/user_timeline .json

How would you properly break this line to match pep8 rules?

谁说我不能喝 提交于 2019-12-05 11:25:30
问题 Given this Python class, implementing a Django form, how would you properly break this to meet the PEP8 standards? class MyForm(forms.Form): categories = forms.CharField(required=False, widget=forms.SelectMultiple(choices=CATEGORY_VALUE), label="Categories") additional_item_ship_cost = forms.CharField(required=False, max_length=10, label="Additional Item Ship Cost") Specifically, the widget= and label= parameters violate the PEP8 rules for line length. What comes to mind immediately is that I

PEP8: conflict between W292 and W391

余生长醉 提交于 2019-12-05 08:35:32
问题 As far as I know in unix it's a good practice to always have blank line at the end of file - or to put it in other words: every line should end with \n . While checking my python code with PEP8 I noticed that it also states that there should be \n at end of file: W292 no newline at end of file JCR: The last line should have a newline. What's strange, it conflicts with W391: W391 blank line at end of file JCR: Trailing blank lines are superfluous. Okay: spam(1) W391: spam(1)\n How it should be

How to make Vim error list permanent using PyFlakes?

☆樱花仙子☆ 提交于 2019-12-05 01:47:20
问题 I want to use pep8 as my makeprg in order to check and fix my code compliance to PEP8 (Style guide for python code). I used the command :set makeprg=pep8\ --repeat\ % , and when I do :make it works, the error list is populated and I can use :cn , :cp and :copen to navigate and see the error list in the QuickFix window. But as soon as I change something in my python source file the errorlist becomes empty, the QuickFix window loses its content and I cannot navigate the list anymore. I suspect