Notice: While JavaScript is not essential for this website, your interaction with the content will be limited. Please turn JavaScript on for the full experience.
...sum(x for x in foo()). Now suppose there's a bug in foo() that raises an exception, and a bug in sum() that raises an exception before it starts iterating over its argument. Which exception would you expect to see? I'd be surprised if the one in sum() was raised rather the one in foo(), since the call to foo() is part of the argument to sum(), and I expect arguments to be processed before the function is called. OTOH, in sum(bar(x) for x in foo()), where sum() and foo() are bugfree, but bar() r...
...sum? This proved to be the most controversial part of the reference implementation. In one sense, clearly three sums is two too many. But in another sense, yes. The reasons why the two existing versions are unsuitable are described here [23] but the short summary is: the built-in sum can lose precision with floats; the built-in sum accepts any non-numeric data type that supports the + operator, apart from strings and bytes; math.fsum is high-precision, but coerces all arguments to float. Ther...
Version: None
Released: April 4, 2023
This is an early developer preview of Python 3.12. Major new features of the 3.12 series, compared to 3.11 Python 3.12 is still in development. This release, 3.12.0a7 is the seventh and final alpha release of 3.12. Alpha releases are intended to make it easier to test the current …
...sum() - a new function to sum a sequence of numbers. "sum(seq, start)" is faster and easier to understand than "reduce(operator.add, seq, start)". (New in 2.3b1.) enumerate() - an iterator taking a sequence returning tuples of (index, item). This solves the old "for i in range(len(seq))" problem more elegantly. (PEP 279) basestring - an abstract string type which is the base class for str (8-bit strings) and unicode. Primarily used to simplify tests for string-n...
Released: April 5, 2023
This is the eleventh maintenance release of Python 3.10 Python 3.10.10 is the newest major release of the Python programming language, and it contains many new features and optimizations. Major new features of the 3.10 series, compared to 3.9 Among the new major new features and changes so far: PEP …
View Release Notes
...sume from a known point, while the other independent iterator can be freely advanced to "explore" a further part of the sequence as needed. A simple example: a generator function which, given an iterator of numbers (assumed to be positive), returns a corresponding iterator, each of whose items is the fraction of the total corresponding to each corresponding item of the input iterator. The caller may pass the total as a value, if known in advance; otherwise, the iterator returned by calling thi...
...Summary A one-line summary of what the distribution does. Example: Summary: A module for collecting votes from beagles. Description (optional) A longer description of the distribution that can run to several paragraphs. Software that deals with metadata should not assume any maximum size for this field, though people shouldn't include their instruction manual as the description. The contents of this field can be written using reStructuredText markup [1]. For programs that work with the met...
...sumes that this is a one-horse distribution named after its sole module (mymod). Those who enjoy defining subclasses might prefer to phrase this differently: from distutils.core import Distribution, setup class MyDistribution (Distribution): name = "mymod" version = "1.2", author = "Greg Ward <gward@cnri.reston.va.us>", description = "A very simple, one-module distribution") setup (distclass = MyDistribution) Thi...
...summing them. The stats are presented in daily or monthly files, under /stats/days and /stats/months. Each file is a bzip2 file with these formats: YYYY-MM-DD.bz2 for daily files YYYY-MM.bz2 for monthly files Examples: /stats/days/2008-11-06.bz2 /stats/days/2008-11-07.bz2 /stats/days/2008-11-08.bz2 /stats/months/2008-11.bz2 /stats/months/2008-10.bz2 Mirror Authenticity With a distributed mirroring system, clients may want to verify that the mirrored copies are authentic. There are multipl...
...sum of local variables and stack usage for a code object. The number of classes in a running interpreter. The recursion depth of Python code. It is likely that memory constraints would be a limiting factor before the number of classes reaches one million. Recursion depth The recursion depth limit only applies to pure Python code. Code written in a foreign language, such as C, may consume hardware stack and thus be limited to a recursion depth of a few thousand. It is expected that implementati...
...sums(data, start=0) ... total = start ... yield from (total += value for value in data) ... return total ... >>> print(list(cumulative_sums(range(5)))) [0, 1, 3, 6, 10] While the following examples would all raise TargetNameError: class C: cls_target = 0 incr_cls_target = lambda: cls_target += 1 # Error due to class scope def missing_target(): incr_x = lambda: x += 1 # Error due to missing target "x" def late_target(): incr_x = lambda: x += 1 # Error due to ...
...sum of the lists [C] + [C1, C2, ... ,CN]. Now I can explain how the MRO works in Python 2.3. Consider a class C in a multiple inheritance hierarchy, with C inheriting from the base classes B1, B2, ... , BN. We want to compute the linearization L[C] of the class C. The rule is the following: the linearization of C is the sum of C plus the merge of the linearizations of the parents and the list of the parents. In symbolic notation: L[C(B1 ... BN)] = C + merge(L[B1] ... L[BN], B1 ... BN) In par...
...summing iterables into a list, such as my_list + list(my_tuple) + list(my_range) which is now equivalent to just [*my_list, *my_tuple, *my_range]. Specification Function calls may accept an unbounded number of * and ** unpackings. There will be no restriction of the order of positional arguments with relation to * unpackings nor any restriction of the order of keyword arguments with relation to ** unpackings. Function calls continue to have the restriction that keyword arguments must follow p...
...summarization: print "Total rainfall", sum(rain) Using zip(*args) is more easily coded if zip(*[]) is handled as an allowable case rather than an exception. This is especially helpful when data is either built up from or recursed down to a null case with no records. Seeing this possibility, the BDFL agreed (with some misgivings) to have the behavior changed for Py2.4. Other Changes The xzip() function discussed above was implemented in Py2.3 in the itertools module as itertools.izip(). Th...
...sumes that mutual respect and the best intentions will always lead to consensus, and that the Code of Conduct governs all interactions and discussions. The role of the GUIDO One of the most important roles of the GUIDO is to provide an overarching, broad, coherent vision for the evolution of the Python language, spanning multiple releases. This is especially important when decision have lasting impact and competing benefits. For example, if backward incompatible changes to the C API leads to...
...summing two rationals (which take O(M) and O(N) space respectively) gives a rational which takes O(M+N) memory space is just too troublesome. There are excellent Rational implementations in both pure Python and as extensions (e.g., gmpy), but they'll always be a "niche market" IMHO. Probably worth PEPping, not worth doing without Decimal -- which is the right way to represent sums of money, a truly major use case in the real world. Anyway, if you're interested in this data type, you maybe will ...
...sum of all primes below 100000, again sharing nothing: cmd: run_benchmarks.py crunch_primes.py Importing crunch_primes Starting tests ... non_threaded (1 iters) 0.495157 seconds threaded (1 threads) 0.522320 seconds processes (1 procs) 0.523757 seconds non_threaded (2 iters) 1.052048 seconds threaded (2 threads) 1.154726 seconds processes (2 procs) 0.524603 seconds non_threaded (4 iters) 2.104733 seconds threaded (4 threads) 2.455215 seconds processes (4 procs) 0.53068...
...sumed that: All of these features should have an identical set of supported radices, for consistency. Python source code syntax and int(mystring, 0) should continue to share identical behavior. Removal of old octal syntax This PEP proposes that the ability to specify an octal number by using a leading zero will be removed from the language in Python 3.0 (and the Python 3.0 preview mode of 2.6), and that a SyntaxError will be raised whenever a leading "0" is immediately followed by another di...
...sumers can do anything they want with a function's annotations. For example, one library might use string-based annotations to provide improved help messages, like so: def compile(source: "something compilable", filename: "where the compilable thing comes from", mode: "is this a single statement or a suite?"): ... Another library might be used to provide typechecking for Python functions and methods. This library could use annotations to indicate the function's ex...