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.
...searchable archive on the ActiveState site which is also hosting the famous Python Cookbook. The python tutor mailing list is useful to beginners learning the language and looking for answers to their programming problems; educators are welcome to join as volunteers; the edu-sig mailing list is more for discussions about uses of Python in educational settings. Free books and tutorials for educators There are a number of freely available tutorials for Python. For example, there is a collection...
...search path elements. These finders' find_module methods return either a "loader" object or None. For a finder to contribute to namespace packages, it must implement a new find_loader(fullname) method. fullname has the same meaning as for find_module. find_loader always returns a 2-tuple of (loader, <iterable-of-path-entries>). loader may be None, in which case <iterable-of-path-entries> (which may be empty) is added to the list of recorded path entries and path searching continue...
...algorithm was switched from right-to-left to left-to-right, which is more efficient for small bases. In addition, if the exponent is large, the algorithm now does 5 bits (instead of 1 bit) at a time. That cut the time to compute 17**1000000 on my box in half again, down to about 4.5 seconds. OverflowWarning is no longer generated. PEP 237 scheduled this to occur in Python 2.3, but since OverflowWarning was disabled by default, nobody realized it was still being generated. On the chance that ...
...algorithms that use a dictionary as a bag of "to do" items and repeatedly need to pick one item. Such algorithms normally end up running in quadratic time; using popitem() they can usually be made to run in linear time. Standard library In the time module, the time argument to the functions strftime, localtime, gmtime, asctime and ctime is now optional, defaulting to the current time (in the local timezone). The ftplib module now defaults to passive mode, which is deemed a more us...
...searched systematically to find the most suitable adapter. But that's about all I know of the subject, and I think it should remain a nice idea, until we have a standard way to talk about interfaces. So I think this will have "frozen" status (see above) at least as long as PEP 245. I have to admit that I never read the whole PEP, and certainly never tried to read and understand the specification or the sample implementation, so maybe I'm still off base. PEP 254 - Making Classes...
...searching for and checking the versions of all the individual libraries listed in the manylinux1 profile, etc.), but ultimately decided that this would be more likely to introduce confusing bugs than actually help the user. (For example: different distributions vary in where they actually put these libraries, and if our checking code failed to use the correct path search then it could easily return incorrect answers.) PyPI Support PyPI should permit wheels containing the manylinux1 platform ta...
...searching for a file to meet that need. You must specify --no-deps as an argument to pip to prevent unintended dependency resolution outside of the requirements file. Fourth, the format allows for installing a source distribution file (aka "sdist"). By its very nature, installing an sdist requires executing arbitrary Python code, meaning that there is no control over what files may be installed. Only by specifying --only-binary :all: can you guarantee pip to only use a wheel file for each packag...
...algorithm for generating the machine-readable simple/ index. The modes are: pypi-scrape-crawl: no change from the current situation of generating machine-readable links for installation tools, as outlined in the history. pypi-scrape: for a package in this mode, links to be added to the simple/ index are still scraped from package metadata. However, the "Home-page" and "Download-url" links are given rel=ext-homepage and rel=ext-download attributes instead of rel=homepage and rel=download. The ef...
...algorithm is now used. This is most effective if the inputs have roughly the same size. If they both have about N digits, Karatsuba multiplication has O(N**1.58) runtime (the exponent is log_base_2(3)) instead of the previous O(N**2). Measured results may be better or worse than that, depending on platform quirks. Besides the O() improvement in raw instruction count, the Karatsuba algorithm appears to have much better cache behavior on extremely large integers (starting in the ballpark of a ...
...search(pat, text): print("Found:", match.group(0)) # The same syntax chains nicely into 'elif' statements, unlike the # equivalent using assignment statements. elif match := re.search(otherpat, text): print("Alternate found:", match.group(0)) elif match := re.search(third, text): print("Fallback found:", match.group(0)) # Reading socket data until an empty string is returned while data := sock.recv(8192): print("Received data:", data) Particularly with the while loop, this can ...
...algorithm or application state. This is an especially useful technique when passing multi-line functions to operations which take callable arguments. keep given clauses concise. If they become unwieldy, either break them up into multiple steps or else move the details into a separate function. Rationale Function and class statements in Python have a unique property relative to ordinary assignment statements: to some degree, they are declarative. They present the reader of the code with some ...
...algorithm that the tool considers too weak to trust, automated tools SHOULD at least emit a warning and MAY refuse to rely on the URL. If such a direct reference also uses an insecure transport, automated tools SHOULD NOT rely on the URL. It is RECOMMENDED that only hashes which are unconditionally provided by the latest version of the standard library's hashlib module be used for source archive hashes. At time of writing, that list consists of 'md5', 'sha1', 'sha224', 'sha256', 'sha384', and 's...
...algorithm used by some builtin types While the first of those behaviours is arguably desirable (and consistent with the existing behaviour of os.urandom on other operating systems), the latter two behaviours are unnecessary and undesirable, and the last one is now known to cause a system level deadlock when attempting to run Python scripts during the Linux init process with Python 3.5.0 or 3.5.1 [2], while the second one can cause problems when using virtual machines without robust entropy sour...
...search, and allow the community to reap the most benefit from our research. Benefits of early and large-scale community involvement for our research will include: volunteers who help "test-drive" our courses and software prototypes; new courses developed by community members aimed at specific target audiences or aimed at teaching specific skills or subjects; localized variants, translations etc. of existing courses; new or modified examples (you can never have enough examples, and examples...
...algorithms used to implement this PEP, as well as the necessary changes to CPython. For the purpose of this section, we define execution context as an opaque container of non-local state that allows consistent access to its contents in the concurrent execution environment. A context variable is an object representing a value in the execution context. A call to contextvars.ContextVar(name) creates a new context variable object. A context variable object has three methods: get(): returns the v...