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.
...record. Proposal This proposal introduces a syntax extension to the print statement, which allows the programmer to optionally specify the output file target. An example usage is as follows: print >> mylogfile, 'this message goes to my log file' Formally, the syntax of the extended print statement is: print_stmt: ... | '>>' test [ (',' test)+ [','] ] ) where the ellipsis indicates the original print_stmt syntax unchanged. In the extended form, the expression just after >&g...
...definitions, but just one big technical change: the Stable ABI will be explicitly listed in a human-maintained “manifest” file. There have been efforts to collect such lists automatically, e.g. by scanning the symbols exported from Python. Such automation might seem easier to maintain than a handcrafted file, but has major issues: for example, the set exported symbols has platform-specific variations. Also, the cost of updating an explicit manifest is small compared to the overall work that shou...
...record. Motivation Standard for-loops in Python iterate over the elements of a sequence [1]. Often it is desirable to loop over the indices or both the elements and the indices instead. The common idioms used to accomplish this are unintuitive. This PEP proposes two different ways of exposing the indices. Loop counter iteration The current idiom for looping over the indices makes use of the built-in range function: for i in range(len(sequence)): # work with index i Looping over both ...
...definitions of itervalues() and iteritems() (along with essentially redundant definitions of iterkeys()). Creating your own definitions of these functions in a custom compatibility module is also relatively straightforward: try: dict.iteritems except AttributeError: # Python 3 def itervalues(d): return iter(d.values()) def iteritems(d): return iter(d.items()) else: # Python 2 def itervalues(d): return d.itervalues() def iteritems(d): r...
...recording "Subversion, CVS, or RCS" version strings using keyword expansion. In the PEP author's own email archives, the earliest example of the use of an __version__ module attribute by independent module developers dates back to 1995. Another example of version information is the sqlite3 [5] module with its sqlite_version_info, version, and version_info attributes. It may not be immediately obvious which attribute contains a version number for the module, and which contains a version number ...
...record. Proposed Semantics The proposed patch that adds augmented assignment to Python introduces the following new operators: += -= *= /= %= **= <<= >>= &= ^= |= They implement the same operator as their normal binary form, except that the operation is done in-place when the left-hand side object supports it, and that the left-hand side is only evaluated once. They truly behave as augmented assignment, in that they perform all of the normal load and store operations, in addi...
...definition and C extension ABI, and the desire to get new features (most notably standard library updates) into user's hands more quickly. With the standard library release cycle decoupled (to some degree) from that of the core language definition, it provides an opportunity to actually slow down the rate of change in the language definition. The language moratorium for Python 3.2 effectively slowed that cycle down to more than 3 years (3.1: June 2009, 3.3: August 2012) without causing any major...
...definition 'raw-unicode-escape': See Unicode Constructors for a definition 'native': Dump of the Internal Format used by Python Common aliases should also be provided per default, e.g. 'latin-1' for 'iso-8859-1'. Note: 'utf-16' should be implemented by using and requiring byte order marks (BOM) for file input/output. All other encodings such as the CJK ones to support Asian scripts should be implemented in separate packages which do not get included in the core Python distribution a...
...record. Background The semantics for Python instances allow the programmer to customize some aspects of attribute lookup and attribute modification, through the special methods __getattr__() and __setattr__() [1]. However, because of certain restrictions imposed by these methods, there are useful programming techniques that can not be written in Python alone, e.g. strict Java Bean-like [2] interfaces and Zope style acquisitions [3]. In the latter case, Zope solves this by including a C extens...
...recorded and the scan continues with the next directory in the parent path. Otherwise the scan continues with the next directory in the parent path. If the scan completes without returning a module or package, and at least one directory was recorded, then a namespace package is created. The new namespace package: Has a __path__ attribute set to an iterable of the path strings that were found and recorded during the scan. Does not have a __file__ attribute. Note that if "import foo" is execute...
...record. List ranges Ranges are sequences of numbers of a fixed stepping, often used in for-loops. The Python for-loop is designed to iterate over a sequence directly: >>> l = ['a', 'b', 'c', 'd'] >>> for item in l: ... print item a b c d However, this solution is not always prudent. Firstly, problems arise when altering the sequence in the body of the for-loop, resulting in the for-loop skipping items. Secondly, it is not possible to iterate over, say, every second e...
...definitions else: # Python 2 specific definitions if sys.platform == 'win32': # Windows specific definitions else: # Posix specific definitions Don't expect a checker to understand obfuscations like "".join(reversed(sys.platform)) == "xunil". Runtime or type checking? Sometimes there's code that must be seen by a type checker (or other static analysis tools) but should not be executed. For such situations the typing module defines a constant, TYPE_CHECKING, that is considered Tr...
...definition overrides the dynamic definition, but for other attributes, dynamic overrides static. Rationale: we can't have a simple rule like "static overrides dynamic" or "dynamic overrides static", because some static attributes indeed override dynamic attributes; for example, a key '__class__' in an instance's __dict__ is ignored in favor of the statically defined __class__ pointer, but on the other hand most keys in inst.__dict__ override attributes defined in inst.__class__. Presence of a _...
...definitions Integration and deployment of distributions Development and publication of distributions Metadata format Metadata files Metadata validation Core metadata Metadata version Generator Name Version Summary Source code metadata Source labels Source URL Semantic dependencies Mapping dependencies to development and distribution activities Extras Dependencies Metadata Extensions Extension versioning Required extension handling Extras (optional dependencies) Updating the metadata ...
...Record of reStructuredText Syntax Alternatives records markup decisions made independently. Docstring-Significant Features A markup escaping mechanism. Backslashes (\) are used to escape markup characters when needed for non-markup purposes. However, the inline markup recognition rules have been constructed in order to minimize the need for backslash-escapes. For example, although asterisks are used for emphasis, in non-markup contexts such as "*" or "(*)" or "x * y", the asterisks are not ...
...definition must be agreed upon in order to facilitate a discussion on the topic of this PEP. A package is something you install as a dependency and use via the import system. The packages on PyPI are an example of this. An application or app is an end product that other external code does not directly rely on via the import system (i.e. they are standalone). Desktop applications, command-line tools, etc. are examples of applications. A lock file records the packages that are to be installed for ...
...definition syntax, you are free to use inheritance, metaclasses, docstrings, user-defined methods, class factories, and other Python class features. A class decorator is provided which inspects a class definition for variables with type annotations as defined in PEP 526, "Syntax for Variable Annotations". In this document, such variables are called fields. Using these fields, the decorator adds generated method definitions to the class to support instance initialization, a repr, comparison met...
...definitions, so does this allow exception catching in an expression context. This provides a clean and consistent way for a function to provide a default: it simply raises an appropriate exception, and the caller catches it. With some situations, an LBYL technique can be used (checking if some sequence has enough length before indexing into it, for instance). This is not safe in all cases, but as it is often convenient, programmers will be tempted to sacrifice the safety of EAFP in favour of the...
...record of the January 20, 2013 meeting Approved, 9-0-1. 3 Votes Taken Between Meetings There were no votes taken between meetings. 4 Votes Taken Over Email There were no votes taken over email. 5 Reports 5.1 Event Coordinator Report Continued Activities from Last Month Housing Management: I have signed a contract with Marriott Suites for financial aid housing. Since we are almost sold out at the Westin and Hyatt, we m...
...record of the November 11, 2021 meeting. Approved, 7-0-3, 2022-01-25 RESOLVED, that the Python Software Foundation approve the minutes at https://mail.python.org/archives/list/psf-important@python.org/thread/YLOR5YLGF7LPQBDXTATLXIYVZEWBHCJJ/ as representing a true and accurate record of the November 9, 2021 meeting. Approved, 9-0-1, 2022-01-25 RESOLVED, that the Python Software Foundation approve the minutes at https://mail.python.org/archives/list/psf-important@python.org/message/WUK6...