pep8

How to tell Spyder's style analysis PEP8 to read from a setup.cfg or increase max. line length?

Deadly 提交于 2019-12-18 18:54:15
问题 I am using Spyder 2.3.1 and python(x, y). In the preferences of Spyder you can activate "Style analysis". This is quite nice, but I want to increase the max. tolerable line length. The standard setting for PEP8 is 79 characters. This can be changed through a setup.cfg with the content: [pep8] max-line-length = 99 This can be read here: http://pep8.readthedocs.org/en/latest/intro.html#related-tools Where do I put a setup.cfg so Spyder/PEP8 will recognize my new limit? Or is there an other way

Triple-double quote v.s. Double quote

我的梦境 提交于 2019-12-18 12:08:43
问题 What is the preferred way to write Python doc string? """ or " In the book Dive Into Python, the author provides the following example: def buildConnectionString(params): """Build a connection string from a dictionary of parameters. Returns string.""" In another chapter, the author provides another example: def stripnulls(data): "strip whitespace and nulls" return data.replace("\00", "").strip() Both syntax work. The only difference to me is that """ allows us to write multi-line doc. Is

Is there a recommended format for multi-line imports?

£可爱£侵袭症+ 提交于 2019-12-18 10:14:46
问题 I have read there are three ways for coding multi-line imports in python With slashes: from Tkinter import Tk, Frame, Button, Entry, Canvas, Text, \ LEFT, DISABLED, NORMAL, RIDGE, END Duplicating senteces: from Tkinter import Tk, Frame, Button, Entry, Canvas, Text from Tkinter import LEFT, DISABLED, NORMAL, RIDGE, END With parenthesis: from Tkinter import (Tk, Frame, Button, Entry, Canvas, Text, LEFT, DISABLED, NORMAL, RIDGE, END) Is there a recomended format or a more elegant way for this

How do I set the maximum line length in PyCharm?

断了今生、忘了曾经 提交于 2019-12-18 09:58:08
问题 I am using PyCharm on Windows and want to change the settings to limit the maximum line length to 79 characters, as opposed to the default limit of 120 characters. Where can I change the maximum amount of characters per line in PyCharm? 回答1: Here is screenshot of my Pycharm. Required settings is in following path: File -> Settings -> Editor -> Code Style -> General: Right margin (columns) 回答2: For PyCharm 2018.1 on Mac: Preferences ( ⌘ + , ), then Editor -> Code Style : For PyCharm 2018.3 on

Enable pep8 in Eclipse

只愿长相守 提交于 2019-12-17 21:06:26
问题 I enabled PEP8 in my Eclipse Luna for a pydev project and it works if I create a new file but it doesn't work for an existing project/file. I enabled PEP8 in window> preferences > pydev > editor > codeAnalysis > pep8.py > warning and I tried to click right onto my project folder > pydev > code analysis But unfortunately it doesn't work. 回答1: PyDev will only analyze valid packages in the PYTHONPATH (i.e.: under a source folder). So, Are your sources in the existing project under a source

What is PEP8's E128: continuation line under-indented for visual indent?

ぐ巨炮叔叔 提交于 2019-12-17 14:58:55
问题 Just opened a file with Sublime Text (with Sublime Linter) and noticed a PEP8 formatting error that I'd never seen before. Here's the text: urlpatterns = patterns('', url(r'^$', listing, name='investment-listing'), ) It's flagging the second argument, the line that starts url(...) I was about to disable this check in ST2 but I'd like to know what I'm doing wrong before I ignore it. You never know, if it seems important I might even change my ways :) 回答1: PEP-8 recommends you indent lines to

Use case for “import as” in Python

百般思念 提交于 2019-12-12 16:09:41
问题 I am wondering if we can use " import as " for creating relatively compact or readable code. I am aware of its usual use cases based on PEP such as to void name clashes. Here is the situation (keeping it very simple for the demonstration purpose). Let's say I have a module name, process_words.py. process_words.py: def word_to_lower(word): return word.lower process_article.py (lets the main script): import process_words word = "HELLO" word_lower = process_words.word_to_lower(word) print(word

What is the recommended layout for splitting ternary operator into multiple lines?

谁说胖子不能爱 提交于 2019-12-11 14:11:34
问题 To improve code readability I need to split my ternary operator expression into multiple lines. My only idea is something like this: very_long_function_name( ... very_long_expression_if_the_condition_is_true if the_condition else another_expression_if_the_condition_is_false) Unfortunately PyCharm claims that continuation line over-indented for visual indent is a violation of PEP8. When I wrap the operator in braces PyCharm raises no objections, but IMHO the code is less readable then. Is

Do I have to deviate from PEP 8 style conventions when comparing to booleans in pandas?

北城以北 提交于 2019-12-11 07:03:47
问题 I used to the following when altering a dataframe column based on a condition (in this case, every woman gets a wage of 200). import pandas as pd df = pd.DataFrame([[False,100],[True,100],[True,100]],columns=['female','wage']) df.loc[df['female'] == True,'wage'] = 200 The PEP 8 Style convention checker (in Spyder) recommends in line 3: comparison to True should be 'if cond is True:' or 'if cond:' Changing the last row to df.loc[df['female'] is True,'wage'] = 200 yields KeyError: 'cannot use a

Idiomatic Python - checking for zero

断了今生、忘了曾经 提交于 2019-12-11 06:16:54
问题 What is the idiomatic way for checking a value for zero in Python? if n == 0: or if not n: I would think that the first one is more in the spirit of being explicit but on the other hand, empty sequences or None is checked similar to the second example. 回答1: If you want to check for zero, you should use if n == 0 . Your second expression doesn't check for zero, it checks for any value that evaluates as false. I think the answer lies in your requirements; do you really want to check for zero,