Questions tagged [pep]

Python Enhancement Proposals are used to propose and document Python language features, development processes and best practices. Use [pep8] for questions about the style guide for Python code.

Python Enhancement Proposals are used to propose and document Python language features, development processes and best practices.

Some important PEPs are:

At a given moment, the status of a PEP can be any one of Draft, Deferred, Accepted, Rejected, Withdrawn, Accepted, Final or Replaced. Informational PEPs which are expected to continue being updated may alternatively have a status of Active.

This flowchart shows how the status of a PEP may evolve:

enter image description here

A public Mercurial repository contains a record of changes to PEPs.

Use for questions about the style guide for Python code.

243 questions
0
votes
2 answers

How to test individual characters of a bytes string object?

Let's say we want to test if the first character of b"hello" is a b"h": s = b"hello" print(s[0] == b"h") # False <-- this is the most obvious solution, but doesn't work print(s[0] == ord(b"h")) # True, but not very explicit What is the most…
Basj
  • 41,386
  • 99
  • 383
  • 673
0
votes
3 answers

How do I find if a PEP has already been written and rejected?

As an example, in Python I often mind myself writing: if failed: raise SomethingFailed(failed) or even if ready: return result Wouldn't it be nice if I could write? while True raise SomethingFailed(failed) if failed return result if…
Francis Cagney
  • 301
  • 1
  • 10
0
votes
0 answers

Is there a PEP styleguide for class member initialization?

Assuming I want to initialize every member variable in __init__, is there a recommended approach or style according to PEP? Especially for classes where the constructor also calls methods and has a bunch of member variables, I currently use the…
mm rnm
  • 47
  • 4
0
votes
1 answer

Pure Python abc/ABCMeta implementation?

It would be interesting to read the original pure Python implementation of abc module, described in PEP 3119. Unfortunately, the link to a sample implementation from original PEP leads to a password protected SVN repository on python.org. I don't…
lithuak
  • 6,028
  • 9
  • 42
  • 54
0
votes
2 answers

What's the best Python string split approach?

I am refactoring some python code and have noticed the original creator has been calling the split method each time they need an element from the resulting split list, rather than storing the split result as a variable. I am wondering if there is…
hs14428
  • 109
  • 5
0
votes
2 answers

Absolute imports can provide all the functionality of relative (intra-package) imports?

I'm reading PEP328: The python-dev community chose absolute imports as the default because they're the more common use case and because absolute imports can provide all the functionality of relative (intra-package) imports -- albeit at the cost of…
NeoZoom.lua
  • 2,269
  • 4
  • 30
  • 64
0
votes
1 answer

Is this an acceptable Python naming convention?

I am currently learning some advanced Python at school, and my teacher has recommended the use of PascalCase for all variable, function, and class names. He says that since all Python keywords are lowercase, this convention will help to…
stadepalli
  • 29
  • 6
0
votes
1 answer

What is the best way to import local modules?

"What are the PEP-compatible ways to import a local package even from a parent folder with the least preassumptions" could be the long title. I am looking for a solution to make it possible to use a local package. My requirements: it must be…
DanielTuzes
  • 2,494
  • 24
  • 40
0
votes
2 answers

Python, Casting a list from a set changes the order. What is the best way to avoid this?

Given this python code snippet: import numpy as np rng = np.random.default_rng(42) class Agent: def __init__(self, id): self.id = id self.friends = set() def __repr__(self): return str(self.id) group_list =…
0
votes
1 answer

Where does it say that 0x prefix makes literals hex base?

I know that I can write 0x1230FF in Python and it will be a literal int with the value 1192191. But I can't find anything in the official docs or the PEPs that specifies that this is allowed and that 0x indeed denotes a hex radix. The closest I…
Laurenz
  • 1,810
  • 12
  • 25
0
votes
2 answers

How can I handle this PEP8 warning?

I have a two-line code like this: if validated_data.get('is_shipped') == False: # 管理员取消了发货,则把物流信息删掉 validated_data.update(logistics_company=None, logistics_tracking_no=None) I am using Pycharm and the PEP8 check is on. So there is an underline…
Gorgine
  • 310
  • 2
  • 11
0
votes
1 answer

Python: official guidance on using single dispatch functions

I just learned about the @singledispatch operator from functools. My first thought was that I would now be using this everywhere, because I write functions like this a lot. But I have been using Python for a couple years now and had never…
Leo Ware
  • 109
  • 4
0
votes
1 answer

How can you square a number in pep9?

I am trying to multiply a number by itself in pep9 to get the square of that number. However, I am not sure how to do it as, if I try adding the number by itself at the end, it will give me a random value. Please help. Code: main1: STRO msg4,d …
0
votes
2 answers

Python try-except block re-raising exception

It is bad practice to not capture exceptions of an inner function and instead do it when calling the outer function? Let us look at two examples: Option a) def foo(a, b): return a / b def bar(a): return foo(a, 0) try: bar(6) except…
skd
  • 1,865
  • 1
  • 21
  • 29
0
votes
0 answers

Why do I get a PEP warning asking me to change my equality statement in that context?

I have this line of code: df['volume_up'] = np.where(df['trade_direction'] == True, df['volume'], float('nan')) and I get this warning: but if I change the statement to df['trade_direction'] is True it will not work anymore. Why am I getting this…
Thomas
  • 10,933
  • 14
  • 65
  • 136