pep8

How to fix issues with E402?

本小妞迷上赌 提交于 2019-12-02 04:02:06
问题 We are trying to fix issues with PEP8 E402. Mostly our code is broken on: import os os.environ['LIB_CAN_THROW_ERROR_ON_IMPORT'] = 2 import lib os.environ['LIB_CAN_THROW_ERROR_ON_IMPORT'] = 0 # back - if sys.version_info[0] > 2: import python3lib else: import python2lib - try: import lib except: print('lib is required') sys.exit(1) How to solve these violations? 回答1: The guidelines specified in PEP8 are just that - guidelines. They're a set of rules to follow when they make sense. E402 refers

How to fix issues with E402?

ⅰ亾dé卋堺 提交于 2019-12-02 01:39:17
We are trying to fix issues with PEP8 E402. Mostly our code is broken on: import os os.environ['LIB_CAN_THROW_ERROR_ON_IMPORT'] = 2 import lib os.environ['LIB_CAN_THROW_ERROR_ON_IMPORT'] = 0 # back - if sys.version_info[0] > 2: import python3lib else: import python2lib - try: import lib except: print('lib is required') sys.exit(1) How to solve these violations? The guidelines specified in PEP8 are just that - guidelines. They're a set of rules to follow when they make sense. E402 refers to imports only being at the top of a file. This is to stop the following: import pygame # 800 lines of

Tkinter documentation is contradicting PEP8

南笙酒味 提交于 2019-12-02 01:26:15
问题 PEP 8 states Wildcard imports (from import *) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools. Nonetheless the official documentation is contradicting: to use Tkinter all you need is a simple import statement: import tkinter Or, more often: from tkinter import * Is this a "documentation bug" ? 回答1: I raised bug issue 32830 on this point and the consensus (reached by Python core developers) is that although

What exactly constitutes a constant in Python?

試著忘記壹切 提交于 2019-12-01 13:37:13
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 things like datetime.date objects or strings that are defined at the module level? How about a

Expressions with “== True” and “is True” give different results

微笑、不失礼 提交于 2019-12-01 00:53:19
问题 I have the following MCVE: #!/usr/bin/env python3 import pandas as pd df = pd.DataFrame([True, False, True]) print("Whole DataFrame:") print(df) print("\nFiltered DataFrame:") print(df[df[0] == True]) The output is the following, which I expected: Whole DataFrame: 0 0 True 1 False 2 True Filtered DataFrame: 0 0 True 2 True Okay, but the PEP8 style seems to be wrong, it says: E712 comparison to True should be if cond is True or if cond . So I changed it to is True instead of == True but now it

What is the most pythonic way to open a file?

我怕爱的太早我们不能终老 提交于 2019-11-30 23:11:11
I'm trying to clean up my code a little bit, and I have trouble figuring which of these 2 ways is considered the most pythonic one import os dir = os.path.dirname(__file__) str1 = 'filename.txt' f = open(os.path.join(dir,str1),'r') Although the second seems to be cleanest one, I find the declaration of fullPath a bit too much, since it will only be used once. import os dir = os.path.dirname(__file__) str1 = 'filename.txt' fullPath = os.path.join(dir,str1) f = open(fullPath,'r') In general, is it a better thing to avoid calling functions inside of another call, even if it adds a line of code ?

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

此生再无相见时 提交于 2019-11-30 18:02:43
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 to set this limit or to ignore E501 (line to long)? Just setting "Show vertical line after 99

How to fix: W602 deprecated form of raising exception

本秂侑毒 提交于 2019-11-30 16:57:36
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 Framester 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' . The paren-using form is preferred because when the exception arguments are long or include string

Vim: How to indent to an open paren or bracket when hitting enter?

巧了我就是萌 提交于 2019-11-30 09:02:13
I've been programming Python with Vim for a while but one thing I haven't been able to figure out how to do it set it to auto indent to the level of the last open paren. According to pep8 if you have an open paren and you need to break the line to fit in 80 columns then you're supposed to continue the next line at that open paren. Example: calling_some_really_long_function(that, has, way, too, many, arguments, to, fit, on, one, line) Obviously this is a crazy example, but that's how you're supposed to break your lines in python. What I'd really like to be able to do is set up Vim so that when

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

徘徊边缘 提交于 2019-11-30 07:57:15
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 ignore in pep8 here are all the naming inspections. how to ignore only some of them? I need this because the current project coding guidelines must be kept. It's too hard to change the guidelines of the whole project. I need to disable only some naming inspections. Not all like by "Settings"-> "Editor"-> "Inspections"->"PEP8 coding style