pep8

Python PEP8 printing wrapped strings without indent

巧了我就是萌 提交于 2019-12-04 01:42:56
There is probably an easy answer for this, just not sure how to tease it out of my searches. I adhere to PEP8 in my python code, and I'm currently using OptionParser for a script I'm writing. To prevent lines from going beyond a with of 80, I use the backslash where needed. For example: if __name__=='__main__': usage = '%prog [options]\nWithout any options, will display 10 random \ users of each type.' parser = OptionParser(usage) That indent after the backslash results in: ~$ ./er_usersearch -h Usage: er_usersearch [options] Without any options, will display 10 random users of each type. That

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

孤街醉人 提交于 2019-12-04 00:49:39
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 could define the widget and label outside of the class and then use them in the class definition, but

How to fix: W602 deprecated form of raising exception

杀马特。学长 韩版系。学妹 提交于 2019-12-03 20:33:47
问题 If I use pylint (via sublimerlinter) I get following warning message: W602 deprecated form of raising exception This I how I use exceptions in my code: if CONDITION == True: raise ValueError, HELPING_EXPLANATION 回答1: Raise your exception like this: if CONDITION == True: raise ValueError(HELPING_EXPLANATION) From PEP 8 -- Style Guide for Python Code - Programming Recommendations: When raising an exception, use raise ValueError('message') instead of the older form raise ValueError, 'message' .

How to make Vim error list permanent using PyFlakes?

倖福魔咒の 提交于 2019-12-03 16:24:01
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 that this is caused by PyFlakes, a Vim extension that highlights Python errors on-the-fly. How can I

PyCharm and filters for external tools

左心房为你撑大大i 提交于 2019-12-03 15:30:02
问题 I'm trying out PyCharm for Django development and so far am extremely happy. My team strictly follows PEP8 formatting and we use the pep8 command line program to check to make sure our code conforms. I've configured an external tool command to run pep8 and it works good. I see the capability to create filters that will cause the output to be parsed into something PyCharm can use. I've read the docs and searched Google but can't find an example to make this work. Docs are http://www.jetbrains

For what reason do we have the lower_case_with_underscores naming convention? [closed]

社会主义新天地 提交于 2019-12-03 12:04:40
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . Depending on your interpretation this may or may not be a rhetorical question, but it really baffles me. What sense does this convention make? I understand naming conventions don't necessarily have to have a rhyme or reason behind them, but why deviate from the already

Disable pep8 check in syntastic for python files

别等时光非礼了梦想. 提交于 2019-12-03 11:52:58
问题 I work with enough code that does not follow pep8 (that I cannot fix) and would like syntastic to not use the pep8 syntax checker. Any way to disable it? 回答1: If your are using flake8 as a python syntax checker you could do it like this (put it into your vimrc or ftplugin/python.vim file): let g:syntastic_python_checkers=['flake8'] let g:syntastic_python_flake8_args='--ignore=E501,E225' You need to silence each error class explicitly (and cannot disable pep8 checking as a whole). See the

boolean and type checking in python vs numpy

。_饼干妹妹 提交于 2019-12-03 10:59:40
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 if foo = numpy.bool_(1) , then if foo will evaluate to True while if foo is True will evaluate to

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

南笙酒味 提交于 2019-12-03 09:35:44
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 of add_function : Just add another line between your function definitions : 1 line : 2 lines: This is

How to prevent “too broad exception” in this case?

本小妞迷上赌 提交于 2019-12-03 09:34:57
I got a list of functions that may fail, and if one fail, 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: current_function() except Exception: print(traceback.format_exc()) It's working fine, but it is not PEP8 compliant: When catching exceptions, mention specific exceptions whenever possible instead of using a bare except: clause. For example, use: try: import platform_specific_module except ImportError: platform_specific_module = None A bare