pep8

PEP8 multi-line dict with multi-line value

你说的曾经没有我的故事 提交于 2021-02-10 04:16:27
问题 I use Black for Python, which conforms to PEP8. It removes the indentation from the second line of a two line long value string: mydict = { 'key0': 'value0', 'key1': 'long-two-lines-string-value1-does-not-fit-in-one-line-has-to-continue' 'value1' } to: mydict = { 'key0': 'value0', 'key1': 'long-two-lines-string-value1-does-not-fit-in-one-line-has-to-continue' 'value1', } A colleague questioned this change, and I am wondering if there is any resource/reference that I can use to backup Black's

PEP8 multi-line dict with multi-line value

你。 提交于 2021-02-10 04:15:52
问题 I use Black for Python, which conforms to PEP8. It removes the indentation from the second line of a two line long value string: mydict = { 'key0': 'value0', 'key1': 'long-two-lines-string-value1-does-not-fit-in-one-line-has-to-continue' 'value1' } to: mydict = { 'key0': 'value0', 'key1': 'long-two-lines-string-value1-does-not-fit-in-one-line-has-to-continue' 'value1', } A colleague questioned this change, and I am wondering if there is any resource/reference that I can use to backup Black's

Are docstrings for internal functions (python) necessary? [closed]

烈酒焚心 提交于 2021-02-06 14:47:07
问题 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 3 years ago . Improve this question In python we designate internal function/ private methonds with an underscore at the beginning. Should these functions be documented with docstrings(is it required?)? (the formal documentation i mean, not the one helping the code-reader to understand the

pep8 warning on regex string in Python, Eclipse

雨燕双飞 提交于 2021-02-04 09:23:29
问题 Why is pep8 complaining on the next string in the code? import re re.compile("\d{3}") The warning I receive: ID:W1401 Anomalous backslash in string: '\d'. String constant might be missing an r prefix. Can you explain what is the meaning of the message? What do I need to change in the code so that the warning W1401 is passed? The code passes the tests and runs as expected. Moreover \d{3} is a valid regex. 回答1: "\d" is same as "\\d" because there's no escape sequence for d . But it is not clear

Disable inspection in PyCharm

廉价感情. 提交于 2021-01-29 10:57:41
问题 There are several articles explaining how to disable inspection in PyCharm by clicking my way around. I do not like that because: It does not work for me I have no idea what PyCharm is doing I want to disable PEP8 checking in certain cases, and not be bound to PyCharm In flake8 I can ignore errors with # noqa , but PyCharm does not seem to respect that consistently. How can I tell (in code) PyCharm to ignore errors in a specific line of code? 回答1: If you click alt+enter on the errors, you can

Why should I use CamelCase for namedtuple?

和自甴很熟 提交于 2021-01-28 18:28:17
问题 Assuming this code snippet (ipython) In [1]: from collections import namedtuple In [2]: type(namedtuple) Out[2]: function you can see that factory function namedtuple is a function , of course. I can't see any hint in PEP-8 to use the naming convention for classes in that case. I can only see that the documentation treating it like a class as a naming convention. Why should one use the naming convention for classes in that case? 回答1: You're referring to the use of the name Point for the type

Python for-loop without index and item

天涯浪子 提交于 2021-01-18 04:55:26
问题 Is it possible in python to have a for-loop without index and item? I have something like the following: list_1 = [] for i in range(5): list_1.append(3) The code above works fine, but is not nice according to the pep8 coding guidelines. It says: "Unused variable 'i'". Is there a way to make a for-loop (no while-loop) without having neither the index nor the item? Or should I ignore the coding guidelines? 回答1: You can replace i with _ to make it an 'invisible' variable. See related: What is

What is the PEP8 recommendation for multiple imports from a package?

旧街凉风 提交于 2020-06-15 06:23:11
问题 The PEP8 style guide section on imports seems to be a bit ambiguous. From: https://www.python.org/dev/peps/pep-0008/#imports The first part makes sense: # Imports should usually be on separate lines: # Correct: import os import sys # Wrong: import sys, os But then it goes on to say: # It's okay to say this though: # Correct: from subprocess import Popen, PIPE How should we interpret this? subprocess is a module, so is PEP8 saying it's just OK to import multiple things from a single module on

May __init__ be used as normal method for initialization, not as constructor?

♀尐吖头ヾ 提交于 2020-05-28 21:55:04
问题 Sometimes it looks reasonable to use __init__ as initialization method for already existing object, i.e.: class A(): def __init__(self, x): self.x = x def set_state_from_file(self, file): x = parse_file(file) self.__init__(x) As alternative to this implementation I see the following: class A(): def __init__(self, x): self.init(x) def init(self, x): self.x = x def set_state_from_file(self, file): x = parse_file(file) self.init(x) It seems to me as over-complication of code. Is there any