pep8

Why does PyCharm use 120 Character Lines even though PEP8 Specifies 79?

坚强是说给别人听的谎言 提交于 2020-04-07 17:01:07
问题 PEP8 clearly specifies 79 characters, however, PyCharm defaults to 120 and gives me the warning "PEP8: line too long (... > 120 characters)". Did previous versions of PEP8 use 120 and PyCharm not update its PEP8 checker? I couldn't find any previous versions of the PEP8 Guide, however, I can easily find previous version of the PEP8 Python scripts. I'm starting a new Python project and I'm not sure which to use. References: http://legacy.python.org/dev/peps/pep-0008/ 回答1: PyCharm is built on

Why does PyCharm use 120 Character Lines even though PEP8 Specifies 79?

自闭症网瘾萝莉.ら 提交于 2020-04-07 17:00:47
问题 PEP8 clearly specifies 79 characters, however, PyCharm defaults to 120 and gives me the warning "PEP8: line too long (... > 120 characters)". Did previous versions of PEP8 use 120 and PyCharm not update its PEP8 checker? I couldn't find any previous versions of the PEP8 Guide, however, I can easily find previous version of the PEP8 Python scripts. I'm starting a new Python project and I'm not sure which to use. References: http://legacy.python.org/dev/peps/pep-0008/ 回答1: PyCharm is built on

Chained method calls indentation style in Python [duplicate]

倖福魔咒の 提交于 2020-03-17 03:39:05
问题 This question already has answers here : How to break a line of chained methods in Python? (8 answers) Closed 6 years ago . From reading PEP-8, I get it that you should put the closing parenthesis on the same line as the last argument in function calls: ShortName.objects.distinct().filter( product__photo__stockitem__isnull=False) Probably, long expressions are best to avoid at all. But if it's undesirable, how would you go about multiple chained method calls? Should the closing paren be on a

python pep8 class in init imported but not used

ぃ、小莉子 提交于 2020-02-17 08:26:13
问题 I'm doing PEP8 checks in python using the python flake8 library. I have an import statement in an __init__.py file in one of my sub-modules which looks like this: from .my_class import MyClass The reason I have this line in the init file is so that I can import MyClass from the sub-module as from somemodule import MyClass instead of having to write from somemodule.my_class import MyClass . I would like to know if it is possible to maintain this functionality while correcting the PEP8

Spyder ignores .pycodestyle

自古美人都是妖i 提交于 2020-01-24 11:34:26
问题 I am using Spyder v.3.2.8 and I'm trying to modify the Real-time code style analysis. For example, I'd like to set the max-line-length to 99. I exactly followed what was suggested here, i.e. I created a file .pycodestyle in the directory resulting from import os; os.path.expanduser('~') . The file looks as follows [pycodestyle] ignore = E226,E302,E41,E501,W503 max-line-length = 99 I am aware that ignoring E501 renders max-line-length virtually ineffective. However, I still get warnings if the

Spyder ignores .pycodestyle

爷,独闯天下 提交于 2020-01-24 11:32:48
问题 I am using Spyder v.3.2.8 and I'm trying to modify the Real-time code style analysis. For example, I'd like to set the max-line-length to 99. I exactly followed what was suggested here, i.e. I created a file .pycodestyle in the directory resulting from import os; os.path.expanduser('~') . The file looks as follows [pycodestyle] ignore = E226,E302,E41,E501,W503 max-line-length = 99 I am aware that ignoring E501 renders max-line-length virtually ineffective. However, I still get warnings if the

When is a variable considered constant in terms of PEP8 naming styles?

大兔子大兔子 提交于 2020-01-13 11:11:23
问题 In keeping with PEP8 conventions, in a .py I can define constants as: NAME = "Me" AGE = "Old" GENER = "Male" If a .txt contained Me Old Male on a single line, and in another .py I performed: FILE = "C:/path/to/file.txt" # a declared constant, easy with open(FILE, 'r') as f: content = f.read().rstrip('\n').split() data = ','.join(content) # returns Me,Old,Male Question(s): Can content and data be considered constants? To be constant, must a variable be declared as a constant at build? Or is

What's the correct way to sort Python `import x` and `from x import y` statements?

和自甴很熟 提交于 2019-12-29 02:20:29
问题 The python style guide suggests to group imports like this: Imports should be grouped in the following order: standard library imports related third party imports local application/library specific imports However, it does not mention anything how the two different ways of imports should be laid out: from foo import bar import foo There are multiple ways to sort them (let's assume all those import belong to the same group): first from..import , then import from g import gg from x import xx

Where are detailed the rules, concepts and usages behind each pylint's warnings?

北城余情 提交于 2019-12-25 18:19:51
问题 I am still discovering Pylint and I understand why many Pythonists deactivate some (or many) warnings to lower Pylint 's voice, but for the moment, as a Python newbie I want to use pylint to improve my Pythonic comprehension and my code quality , in order to help me to: learning more from a statement/instruction deepen some concepts evaluate the benefits / drawback of a refactoring etc. So is there a place where all the warning are discussed, justified, explained or they simply came from the

In Python, what to return for no results, False or None?

大憨熊 提交于 2019-12-24 02:16:13
问题 I have a function which searches for results to a query. If there's no results what is recommended to return, False or None? I suppose it's not that important but I'd like to follow best practice. 回答1: I would definitely not return False . But there are other options than just None vs. False . A positive result would be a short string in this case. So, a negative result can be an empty string. (Unless that's also a possible positive result, of course.) As PEP 8 says: For sequences, (strings,