pep8

Multiple right margins in Pycharm

允我心安 提交于 2019-12-05 01:09:00
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. This feature was announced in September 2017 . Go to File -> Settings -> Editor -> Code Style -> Hard wrap at and Visual guides . For visual

How do I enable auto code formatting for flake8 in PyCharm

断了今生、忘了曾经 提交于 2019-12-05 00:02:58
I use Tox to run unit tests, with a flake8 command that checks for code formatting errors. Each time I code in PyCharm, I run tox then realise I have a bunch of annoying formatting errors I have to back and manually fix. I would like PyCharm to automatically format the code (according to flake8 google for me each time it auto-saves after I stop typing. my tox testenv looks like this: [testenv:flake8] commands=flake8 <my_code_directory> deps = flake8==2.4.1 flake8-import-order==0.11 pep8-naming==0.4.1 [flake8] max-line-length = 120 import-order-style = google Is this possible? Do I have to

How to break long string lines for PEP8 compliance? [duplicate]

夙愿已清 提交于 2019-12-04 22:35:45
This question already has answers here : How to write very long string that conforms with PEP8 and prevent E501 (10 answers) Closed 2 years ago . I have many long lines like this in the project and don't know how to break it to keep PEP8 happy. PEP8 shows warning from .format(me['id']) pic_url = "http://graph.facebook.com/{0}/picture?width=100&height=100".format(me['id']) How can I break the line to get rid of PEP8 warning and yet don't break the code? Using string literal concatenation : pic_url = ("http://graph.facebook.com/{0}/" "picture?width=100&height=100".format(me['id'])) 来源: https:/

Store Python PEP8 module output

偶尔善良 提交于 2019-12-04 22:24:31
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 characters) ./test.py:41: [E302] expected 2 blank lines, found 1 ./test.py:53: [E501] line too long (111 > 79

boolean and type checking in python vs numpy

泪湿孤枕 提交于 2019-12-04 18:07:39
问题 I ran into unexpected results in a python if clause today: import numpy if numpy.allclose(6.0, 6.1, rtol=0, atol=0.5): print 'close enough' # works as expected (prints message) if numpy.allclose(6.0, 6.1, rtol=0, atol=0.5) is True: print 'close enough' # does NOT work as expected (prints nothing) After some poking around (i.e., this question, and in particular this answer), I understand the cause: the type returned by numpy.allclose() is numpy.bool_ rather than plain old bool , and apparently

PyCharm shows “PEP8: expected 2 blank lines, found 1”

左心房为你撑大大i 提交于 2019-12-04 16:24:40
问题 Consider the following code: def add_function(a, b): c = str(a) + b print "c is %s" % c def add_int_function(c, d): e = c + d print "the vaule of e is %d" % e if __name__ =="__main__": add_function(59906, 'kugrt5') add_int_function(1, 2) It always shows me: "expected 2 blank lines ,found 1" in a add_int_function , but not in the add_function . When I add two spaces in front of the def add_int_function(c, d): there is a error shows unindent does not match any outer indentation level in the end

Can't get past illogical line pep8 error

倖福魔咒の 提交于 2019-12-04 03:50:14
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] == '(' and regex[-1] == ')' and regex.count('(') > 1): print('hi') I get the following PEP8 error on

Pep8 E501: line too long error

醉酒当歌 提交于 2019-12-04 02:52:08
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?include_entities=true&screen_name=username&count=1 (). or I get this error: ValueError: No JSON object

autopep8 with vim

时光总嘲笑我的痴心妄想 提交于 2019-12-04 02:28:29
Is there a way to automatically apply autopep8 to a file being edited in vim? I have the following vimrc . Thank you in advance. The correct way of using autopep8 is to rely on vim "formatprg" settings. So you add the line below to vimrc: au FileType python setlocal formatprg=autopep8\ - Now when you select lines in python and hit gq (the default mapping unless you remapped it). It will filter the lines through autopep8 and writes the nicely formatted version in place. The setting above also make it work with vim objects and vim motions, so you could rerender a paragraph (well lines of python

What exactly constitutes a constant in Python?

耗尽温柔 提交于 2019-12-04 02:00:17
问题 PEP 8 prescribes that Constants are usually defined on a module level and written in all capital letters with underscores separating words. Examples include MAX_OVERFLOW and TOTAL . I understand that this is a naming convention only, but I'm curious to know if there is an official or widely-accepted definition of what actually constitutes a constant versus a semi-private variable. Is this limited to what you might call mathematical constants? (Namely float, int, complex) Or would it include