python/cpython
View on GitHub ↗ ★ 77,791 Python
The Python programming language
548 mentions on Hacker News by 400 people: 44 stories, 504 comments · first 2014-12-30 · latest 2026-10-27
20082026
-
You don't have to find an alternative. Just copy the parts you need into your own code: https://github.com/python/cpython/blob/main/Lib/cgi.py
comment by iso8859-1 · 2022-03-18 · in Python finally offloads some batteries -
…more than just a single hardware add per Python "add." You can see the actual implementation here: https://github.com/python/cpython/blob/main/Objects/longobje... You've got multiple for loops over every digit, array dereferencing, plus…
comment by nonameiguess · 2022-03-16 · in In the time Python can perform 1 FLOP, an A100 can chew through 9.75M FLOPS -
▲ 2
CPython Listsort (Timsort)story by addcninblue · 2022-03-09 · 0 comments
-
Python is similar[1] >The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ... https://github.com/python/cpython/blob/3.7/Objects/listobjec...
comment by _dain_ · 2022-03-08 · in Buffet – An All-inclusive Buffer for C -
CPython appears to use a PEG parser for its implementation: https://github.com/python/cpython/blob/b77158b4da449ec5b8f68...
comment by linux2647 · 2022-02-20 · in Things that used to be hard and are now easy -
▲ 3
Hash Array Mapped Trie (HAMT) Datastructurestory by pxeger1 · 2022-02-17 · 0 comments
-
…the value of `exit` if you so choose. "Special cases aren't special enough to break the rules." [1] https://github.com/python/cpython/blob/06b8f1615b09099fae5c5...
comment by luhn · 2022-02-06 · in What's in a good error message? -
> CPython does not do these things. Again, it is. https://github.com/python/cpython/blob/2d080347d74078a55c477... This is the memmove() I mentioned above. Like, I actually perf-d the code and confirmed this is in the hot loop. > but 1553D…
comment by rfoo · 2022-02-03 · in Competitive Programming with AlphaCode -
Hmm, it looks like it’s handled comments for at least a decade: https://github.com/python/cpython/blame/d75a51bea3c2442f81d3... Oh, maybe it’s this issue: https://bugs.python.org/issue34132 If I’ve read it correctly, there was a regression…
comment by js2 · 2022-01-24 · in I accidentally used YAML.parse instead of JSON.parse and it worked -
…handled alternative. I filed a PR with a proposed documentation improvement in mid December: https://github.com/python/cpython/pull/30142 Apart from one drive-by comment from a non-core contributor, no-one has commented on the pull request…
comment by jomar · 2022-01-07 · in I found a one-char typo in the docs for Python's typing_extensions library -
…is implemented by constructing _string representations_ of functions and calling `exec` on them. https://github.com/python/cpython/blob/3.10/Lib/dataclasses.... Kind of blew my mind
comment by atorodius · 2021-12-24 · in Attrs – the Python library everyone needs (2016) -
…else (if it even throws anything else?) to be fatal. This is the same way cpython handles it: https://github.com/python/cpython/blob/b56774bd93822e1598bb5... The context manager idea sounds good, but I think that might require a lot of…
comment by postpawl · 2021-12-20 · in Fixing memory leaks in popular Python libraries -
Python's csv imports _csv for core functionality, which is C: https://github.com/python/cpython/blob/main/Modules/_csv.c
comment by __s · 2021-12-16 · in Leveraging SIMD: Splitting CSV Files at 3Gb/S -
…ps://github.com/php/php-src/blob/1c0e613cf1a24cdc159861e4... - Python's C implementation is the same: https://github.com/python/cpython/blob/main/Modules/_csv.c - Java doesn't have a "standard" way at all (…
comment by mschuster91 · 2021-12-16 · in Leveraging SIMD: Splitting CSV Files at 3Gb/S -
The `eval()` in the namedtuple factory function[1] makes it a bit kludgy, IMO. [1]: https://github.com/python/cpython/blob/3.10/Lib/collections/...
comment by woadwarrior01 · 2021-12-12 · in The Data Classes Decorator -
…random probes or by chasing linked list references to random memory locations for each link. https://github.com/python/cpython/blob/f840398a5fd8741653c26...
comment by raymondh · 2021-11-23 · in A Tale of Java Hash Tables -
…more to say about how list resizing works than is immediately obvious. The relevant source is here: https://github.com/python/cpython/blob/main/Objects/listobje... As the article points out, the size progression, as detailed in the comment…
comment by kgm · 2021-11-14 · in How Python List Works -
How a Python list really works? See the underlying C implementation: https://github.com/python/cpython/blob/main/Objects/listobje... ; https://github.com/python/cpython/blob/main/Include/listobje... For comparison, java.util.ArrayList is…
comment by nayuki · 2021-11-14 · in How Python List Works -
…they can easily determine they are the exclusive owner by checking for a reference count of 1. See: https://github.com/python/cpython/blob/main/Objects/unicodeo... Rust's ownership system ensures that there cannot exist mutable and…
comment by MarkSweep · 2021-11-14 · in A terrible schema from a clueless programmer -
…to work with. The setup takes no effort at all and it "just works", batteries included, via ctypes. https://github.com/python/cpython/blob/main/Lib/multiprocess...
comment by perth · 2021-11-10 · in Ask HN: How did Python become the lingua franca of ML/AI? -
…-- it reads as if it will only kick in on linux if it detects a sufficiently new version of glibc: https://github.com/python/cpython/blob/main/Lib/subprocess.p... edit: Python 3.10 now supports using vfork for linux inside subprocess:…
comment by shoo · 2021-11-06 · in In C, how do you know if the dynamic allocation succeeded? -
…or not CPython doesn't have a JIT, it has an interpreter. So it spends a lot of time in this loop: https://github.com/python/cpython/blob/main/Python/ceval.c But you still have a repl with pypy. The downsides of JIT is that compiling…
comment by __s · 2021-11-03 · in Python interpreter written in rust reaches 10000 commits -
Correct link: https://github.com/python/cpython/blob/3.10/Lib/turtle.py#L3...
comment by danbst · 2021-11-03 · in A German Easter Egg in Python Turtle -
▲ 1
A German Easter Egg in Python Turtlestory by danbst · 2021-11-03 · 1 comment
-
…com/clap-rs/clap/pull/1637#issuecomment-58103... [1] https://tldp.org/LDP/abs/html/exitcodes.html [2] https://github.com/python/cpython/blob/main/Lib/argparse.py#...
comment by epage · 2021-11-02 · in Sysexits – preferable exit codes for programs -
…I can cheat and copy anyway since only the non-refcounted ones are allowed in them. [0] https://github.com/python/cpython/blob/main/Include/object.h...
comment by sizediterable · 2021-10-29 · in Building an Emacs Lisp VM in Rust -
I meant actual code from their library So https://github.com/python/cpython/tree/main/Python
comment by savant_penguin · 2021-10-25 · in To learn a new language, read its standard library -
re depends ultimately of this c file https://github.com/python/cpython/blob/main/Modules/_sre.c
comment by makapuf · 2021-10-08 · in Faster Python with Guido van Rossum -
The central dispatch of the VM is a good place to start: https://github.com/python/cpython/blob/main/Python/ceval.c#L...
comment by formerly_proven · 2021-10-06 · in Python 3.11: “Zero cost” exception handling -
…The Zip format is truly awful. https://en.wikipedia.org/wiki/ZIP_(file_format)#Central_dire... https://github.com/python/cpython/blob/7e465a6b8273dc0b6cb48...
comment by jfrunyon · 2021-09-19 · in Reality Check for Cloudflare Wasm Workers and Rust -
From the python source code: https://github.com/python/cpython/blob/11749e2dc20ad6a76e9a3... It seems to be shelling out to osascript, either telling it to OpenURL or open.
comment by zirak · 2021-08-16 · in Antigravity.py (2020) -
▲ 116
Antigravity.py (2020)story by chha · 2021-08-16 · 43 comments
-
…uses a black-box model to explain it rather than looking at the source, `iadd` uses `extend`: https://github.com/python/cpython/blob/main/Objects/listobje...
comment by ndr · 2021-08-13 · in The difference between a=a+b and a+=b in Python -
…Python implementations that get used if the _operator C module is not available for some reason): https://github.com/python/cpython/blob/3.9/Modules/_operator...
comment by JonathonW · 2021-08-08 · in The unknown features of Python's `operator` module -
`methodcaller` ( https://github.com/python/cpython/blob/6a6bcf16370beff2e0d1a... ) is just syntax sugar around `getattr` + a function call which is just syntax sugar + default implementation of `__getattr__` which is basically exactly what…
comment by icegreentea2 · 2021-08-08 · in The unknown features of Python's `operator` module -
…below, you might as well just be using a def, which is exactly what is done in the operator module: https://github.com/python/cpython/blob/3.9/Lib/operator.py#L... For someone familiar with the operator module, there is a final small…
comment by randallsquared · 2021-08-08 · in The unknown features of Python's `operator` module -
The operator module is very old: https://github.com/python/cpython/blob/ea4d3f0804a3aad5afaa6... PEP8 was introduced in 2001: https://www.python.org/dev/peps/pep-0008/
comment by O5vYtytb · 2021-08-08 · in The unknown features of Python's `operator` module -
…does just create a bunch of different Python objects and then use type() to extract their types: https://github.com/python/cpython/blob/v3.9.6/Lib/types.py Some examples from that file: async def _ag(): yield _ag = _ag() AsyncGeneratorType…
comment by simonw · 2021-07-24 · in How the Python import system works -
…3.6 is much more readable than 3.9 so I recommend reading that if you want to see how it works. https://github.com/python/cpython/blob/3.6/Lib/collections/_...
comment by Spivak · 2021-07-21 · in Namedtuple in a Post-Dataclasses World -
See CPython's https://github.com/python/cpython/blob/main/Objects/listsort... for details about the sort. In fact, its "galloping" was inspired by a paper of which Demaine was a co-author (reference in the file already linked to).…
comment by tim-peters · 2021-07-13 · in Beating TimSort at Merging -
Wow. Thanks for writing it. I believe this is the part you are referring to: https://github.com/python/cpython/blob/main/Objects/listobje...
comment by adamgordonbell · 2021-07-13 · in Beating TimSort at Merging -
…be as fast as this implementation? edit: Okay one reason is that heapq.merge is written in python: https://github.com/python/cpython/blob/6252670732c68420c2a8b... It might also be since the python version has more options (like arbitrarily…
comment by CogitoCogito · 2021-07-13 · in Beating TimSort at Merging -
…I'd recommend taking at least a quick look at any python standard library module before using it. https://github.com/python/cpython/tree/main/Lib
comment by vajrabum · 2021-06-30 · in Learn by reading code: Python standard library design decisions explained -
This is the complete code (from here: https://github.com/python/cpython/blob/3.9/Lib/statistics.py ) if iter(data) is data: data = list(data) n = len(data) if n < 1: raise StatisticsError('mean requires at least one data point') T, total,…
comment by mattkrause · 2021-06-30 · in Learn by reading code: Python standard library design decisions explained -
…of strings, so I added an extra layer of caching, but it looks like it's not needed anymore. [1]: https://github.com/python/cpython/blob/3.10/Objects/unicodeo...
comment by ciupicri · 2021-06-13 · in Reducing Python String Memory Use in Apache Arrow 0.12 (2019) -
…>>> data = (1_000_000_000.1, 1.1) * 50_000 >>> statistics.fmean(data) 500000000.6 Implementation at https://github.com/python/cpython/blob/6df926f1c46eb6db7b5dc... .
comment by eesmith · 2021-06-11 · in How to average floating point numbers (2015) -
…_sum function for example, which you can see maps _exact_ratio over the data before summing: https://github.com/python/cpython/blob/3.9/Lib/statistics.py...
comment by _delirium · 2021-06-11 · in How to average floating point numbers (2015) -
…may be slower, but I am hoping that it is easy understand why they ought to be preferred. [1]: https://github.com/python/cpython/blob/5571cabf1b3385087aba2... [2]: https://www.nu42.com/2015/03/how-you-average-numbers.html
comment by nanis · 2021-06-09 · in Perl Data Language: Scientific Computing with Perl -
This has been brought up: https://github.com/python/cpython/pull/26264#discussion_r640... Though personally I would dislike this, since every time somebody mentioned about type hints they commented on the property of them not causing 'ANY…
comment by treesciencebot · 2021-06-02 · in Making CPython Faster -
…Code-ish?[2] Probably not! [1] https://github.com/AdoptOpenJDK/openjdk-jdk11u/blob/master/s... [2] https://github.com/python/cpython/blob/main/Objects/listobje...
comment by throwaway2037 · 2021-05-27 · in It's probably time to stop recommending Clean Code (2020)