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

Use of None and self keywords in method construction

I'm analyzing some old code that I've inherited, and I have a question about the use of "self" and "None" keywords, specifically in the following example: def run(self) -> None: I understand that the self keyword is similar to the "this" keyword in…
Trevor
  • 160
  • 1
  • 12
-1
votes
5 answers

Chaining functions calls on some list

Let's say I have three functions and it needs to process a list one after another. def f1(lst): lst_processed = do_something_of_type1(lst) return lst_processed def f2(lst): lst_processed = do_something_of_type2(lst) return…
utengr
  • 3,225
  • 3
  • 29
  • 68
-1
votes
3 answers

What is more common: X_train or x_train?

What is more common: X_train or x_train? In keras documentation I see 'x_train', while sklearn documentation usually contains 'X_train'. Is there any standard on the notation?
sokolov0
  • 103
  • 5
-1
votes
1 answer

Pytest won't run any tests

I couldn't get pytest to run tests on Python 3.6, so I uninstalled and reinstalled Python 3.7. Then I downloaded pytest and pep8 using pip and added C:\Users\CoolT\AppData\Local\Programs\Python\Python37-32\Scripts to PATH. Now I can't get pytest to…
-1
votes
1 answer

good idea to use list(map(lambda x: xxxx)) without create extra list

I need to send out request one by one by different id and I have following code but I am wondering if it is good idea to use syntax like list(map(lambda x: xxxx), id_list) or i should just use one-for loop for it? id_list = [1,3,4,100,83,99] headers…
jacobcan118
  • 7,797
  • 12
  • 50
  • 95
-1
votes
2 answers

How to shorten the "is not None" in the if statement

In Python3, the Truth Value Testing in PEP8 says that for if A is None:, it can be converted to if not A:. Like so, since the code below looks so messy and hard to grasp at once, can it be expressed more succinct in one way or another? if A is not…
Seungho Lee
  • 1,068
  • 4
  • 16
  • 42
-1
votes
3 answers

PEP8 convention for returning one-line for-loop

Note: this is a convention question; the code does work. That said, I am polishing up an 8 mo. project and can't figure out the best way to style the following: def foo(Xs, Ys, image): products = [] for prod in product(Xs,Ys): …
csindic
  • 69
  • 8
-1
votes
1 answer

Sentence variations in python3

A few months ago I found something with this kind of syntax: {Hello|Dear} {Customer|client|person}, xxxx This will generate sentences like: Hello Customer, or Dear person, How is it called? Is there a framework which parses this? If not, how…
VC_work
  • 145
  • 6
-1
votes
1 answer

IndentationError on breaking a line with binary operators as per the PEP8 guidelines

I'm trying to indent the following line in Python as per the PEP8 guidelines: temperature_rate = (temperature_values[-1] - temperature_values[0]) / (len(temperature_values) * MONITOR_RATE) but I get an IndentationError at this…
Faheel
  • 2,435
  • 24
  • 33
-1
votes
1 answer

PEP8 and base64 strings

The project I'm working on runs a linting check before validating the build. The linter checks PEP8 compliance among other things. I have a base64 string, that's about 5,000 characters long (it's a file converted into a base64 string), and so of…
Verv
  • 2,385
  • 2
  • 23
  • 37
-1
votes
1 answer

When a line of codes is too long, how do I break up the line without \

I have created a few of classes, but these classes have names that are too long (eq: NegativeChannelMetalOxideSemiconductorFieldEffectTransistor). I want to make a new line with \ in python, but in this case it is ugly. In general in Python, when…
员建新
  • 85
  • 1
  • 2
  • 8
-1
votes
1 answer

Sublime3 text can't ignore PEP8 formatting for Python

I installed Sublime for Python programming but I found that PEP8 error detection is pretty annoying and I couldn't get rid of it. I tried this but it's not working: It kept showing this:
odeya
  • 69
  • 6
-1
votes
2 answers

How to improve my coding style for assigning a new value?

Is there a better way to write the third line of following code ? from datetime import date d = date.today() d = d.replace(day=1)
bixente57
  • 1,328
  • 4
  • 14
  • 29
-1
votes
1 answer

pep8 compliant is so confusing me right now

from lab10 import Card from lab10 import ChipBank import random # returns string class BlackjackHand(list): def __str__(self): hand = ' ' for item in self: x = item.get_suit() y = item.get_rank() …
P_P2622
  • 1
  • 3
-1
votes
1 answer

Which is better method to declare regex pattern?

I have python class file. import re regex = { 'a1': re.compile('(\d+)'), } # or A1_REGEX = re.compile('(\d+)') class A1(): def toview(self, mystring): data = regex['a1'].search(mystring) if data: …