Questions tagged [pep8]

Coding conventions and style guidelines for Python. Not to be confused with the PEP/8 assembly language.

PEP (Python Enhancement Proposals) 8 describes coding conventions for code in the standard Python library. This PEP covers how code should be commented, use tabs or spaces to indent code, naming convention, the use of non-semantic white space, etc.

Many large projects have adopted PEP8 (at least in part) as part of their style guides.

The tool pep8 will report code-conformance to the PEP8 guidelines.

Questions tagged as pep8 should relate to how to apply these guidelines to your code.

The full text of PEP8 can be found at python.org.

829 questions
-1
votes
1 answer

combine two assignments in one line and pep8 style python code

email = re.search('(.*?)-+(.*?)-+', line).group(1) password = re.search('(.*?)-+(.*?)-+', line).group(2) user_data.write("%s\t%s\n" % (email, password)) how to combine the first and second line into one line? another question: email =…
kuafu
  • 1,466
  • 5
  • 17
  • 28
-2
votes
3 answers

List comprehension and or spacing with a new-line

This seems like a really simple question; but I can't see how it's actually possible. I normally fairly good my code being PEP8 compliant. 83 characters is fine type of thing. I've got a longish list (dictionary) comprehension combined with an or…
Ben
  • 51,770
  • 36
  • 127
  • 149
-2
votes
1 answer

flake8 & pycodestyle/pep8 not showing E721 errors

Versions λ python --version Python 3.10.6 λ flake8 --version 5.0.4 (mccabe: 0.7.0, pycodestyle: 2.9.1, pyflakes: 2.5.0) CPython 3.10.6 on Linux # and on Windows ## Edit: after update λ flake8 --version 6.0.0 (mccabe: 0.7.0, pycodestyle: 2.10.0,…
Nealium
  • 2,025
  • 1
  • 7
  • 9
-2
votes
2 answers

PEP8 "No newline at end of file"

I'm trying to understand the error below from Flake8: no newline at end of fileFlake8(W292) This is my code below: if __name__ == "__main__": app.run( host=os.environ.get("IP", "0.0.0.0"), port=int(os.environ.get("PORT",…
Ryu
  • 1
  • 1
  • 6
-2
votes
2 answers

Does PEP-8 mandate imports or global variables first?

May I know in a Python environment, which is compliant with PEP-8? Imports before global variables: import some_library GLOBAL_VARIABLE = "something" Or global variables before imports: GLOBAL_VARIABLE = "something" import some_library
LHY
  • 39
  • 4
-2
votes
1 answer

Better code layout in Python to comply with PEP 8 character limit

after my code is finished, I'm trying to improve the readability. Can you help me to improve the readability of the following lines according to PEP 8 regarding the 80 character limit? You see, the part == 'Geburtsdatum' is behind the border. def…
edstrinova
  • 101
  • 1
  • 7
-2
votes
1 answer

Is defining a constant with a loop inside a class compliant with PEP8?

I would like to use a mathematical serie to define a constant inside a class. I would like to know whether this is compliant with the PEP8. Thank you in advance. Please see image below
lucky luke
  • 17
  • 1
-2
votes
1 answer

Python code style: spaces around joinpath operator of pathlib

This bothers me for quite some time. Do you put spaces around join path operator / of pathlib library? Consider the following example: root_dir = Path('root') sub_dir = root_dir / 'folder1' / 'folder2' Since the join operator is still an operator,…
Serhiy
  • 4,357
  • 5
  • 37
  • 53
-2
votes
1 answer

PEP eight in wxpython

I use this code and (wx.SCRIPT, wx.ITALIC, wx.BOLD) are signed as pep8 warning. How can i Fix that? font = wx.Font(9, wx.SCRIPT, wx.ITALIC, wx.BOLD, False, u'Consolas')
Yuval Sharon
  • 159
  • 8
-2
votes
2 answers

Matching indentation level according to PEP8/flake8

The question is how to properly break lines according to PEP8 while using TABs. So here is a related question How to break a line in a function definition in Python according to PEP8. But the issue is that this only works properly when the length…
Matthias Arras
  • 565
  • 7
  • 25
-2
votes
2 answers

Large Nested Loop not Adhering to PEP8 Standards

I am trying to adhere to PEP8 guidelines and one that I am having trouble with is the 79 character line limit. If I am working something like a 10x10 array I tend to use nested loops to access specific elements of the array. It looks like…
-2
votes
3 answers

pep8 has no option to force same indentation in whole code

pep8 assumes that this is a correct style: if True: print 'yes' else: print 'no' http://pep8online.com/s/0VqA3PVj I can not find any error or warning option that make it incorrect. That's too bad to accept such that code. Am I wrong? Is…
iman
  • 21,202
  • 8
  • 32
  • 31
-2
votes
2 answers

What is the PEP8 Standard for Systematic Multi-dimensional (Nested) Arrays?

What is the PEP8 standard for systematic multi-dimensional (nested) arrays? There many ways to structure data in Python, some examples of which are given below. And clearly the 'best' method is the one that meets your needs, even though we have all…
Justin
  • 43
  • 5
-3
votes
1 answer

what is pep 8? How does it help in programming? What are the set of rules regarding that?

what is the Full form and what it is used for? I was going through basics of python when I came across this term. what does it mean by maximum readability?
-3
votes
1 answer

dict.get or list check, which is faster?

If I want to get a bot with an ID, which is faster between: storage = { 'bots': [ { 'id': 123, 'auth': '81792367' }, { 'id': 345, 'auth': '86908472' }, { 'id': 543, 'auth': '12343321' } ] } id = 345 bot =…
1 2 3
55
56