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.
...string A Python type representing a sequence of code points with "string semantics" (e.g. case conversions, regular expression compatibility, etc.) Constructed with the unicode() function. Proposed Solution One solution would be to merely increase the maximum ordinal to a larger value. Unfortunately the only straightforward implementation of this idea is to use 4 bytes per character. This has the effect of doubling the size of most Unicode strings. In order to avoid imposing this cost on ever...
...string representing the target platform for this distribution. This is only for binary distributions. It is encoded as <os_name>-<os_version>-<platform architecture>-<python version>. signature (optional) -- A OpenPGP-compatible signature of the uploaded distribution as signed by the author. This may be used by the cataloging system to automate acceptance of uploads. protocol_version -- A string indicating the protocol version that the client supports. This document d...
...string types, str and unicode, while in Python 3.0 we will only have one string type, whose name will be str but whose semantics will be like the 2.6 unicode type.) Motivation Python's current string objects are overloaded. They serve to hold both sequences of characters and sequences of bytes. This overloading of purpose leads to confusion and bugs. In future versions of Python, string objects will be used for holding character data. The bytes object will fulfil the role of a byte contain...
...strings are surrounded by apostrophes, instances may have both class name and instance data: >>> print([42, '42']) [42, '42'] >>> print([Decimal('42'), datetime.now()]) [Decimal("42"), datetime.datetime(2008, 5, 27, 19, 57, 43, 485028)] The disadvantage is that __repr__ often returns technical data (like '<object at address>') or unreadable string (hex-encoded string if the input is non-ASCII string): >>> print(['ัะตัั']) ['\xd4\xc5\xd3\xd4'] One of the motiva...
...string) -> string It should also be possible to override the help display function by assigning to onlinehelp.displayhelp(object_or_string). The module should be able to extract module information from either the HTML or LaTeX versions of the Python documentation. Links should be accommodated in a "lynx-like" manner. Over time, it should also be able to recognize when docstrings are in "special" syntaxes like structured text, HTML and LaTeX and decode them appropriately. A prototype implemen...
...strings in various formats and returning a corresponding instance of one of the types. This PEP proposes adding a family of predefined parsing function for several commonly used date and time formats, and a facility for generic parsing. The types provided by the datetime module all have .isoformat() and .ctime() methods that return string representations of a time, and the .strftime() method can be used to construct new formats. There are a number of additional commonly-used formats that would ...
...string (i.e. it may appear as the second statement of a module only if the first statement is a STRING+). Backwards Compatibility Introducing directive as a new keyword might cause incompatibilities with existing code. Following the guideline in PEP 5, in the initial implementation of this specification, directive is a new keyword only if it was used in a valid directive_statement (i.e. if it appeared as the first non-string token in a module). Unresolved Problems: directive as the first i...
...string as a value. The presence of a data-yanked attribute SHOULD be interpreted as indicating that the file pointed to by this particular link has been "Yanked", and should not generally be selected by an installer, except under specific scenarios. The value of the data-yanked attribute, if present, is an arbitrary string that represents the reason for why the file has been yanked. Tools that process the simple repository API MAY surface this string to end users. The yanked attribute is not imm...
...strings". String literals occurring immediately after another docstring are called "additional docstrings". Please see PEP 258, "Docutils Design Specification", for a detailed description of attribute and additional docstrings. For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings. For Unicode docstrings, use u"""Unicode triple-quoted strings""". There are two forms of docstrings: one-liners ...
...string containing the URL for the package's home page. Example: Home-page: http://www.example.com/~cschultz/bvote/ Author (optional) A string containing at a minimum the author's name. Contact information can also be added, separating each line with newlines. Example: Author: C. Schultz Universal Features Syndicate Los Angeles, CA Author-email A string containing the author's e-mail address. It can contain a name and e-mail address in the legal forms for a RFC 822 'From...
...string object in its place. Binary files, the struct/array modules, and several other examples exist of this. Putting aside the style issue that these uses typically have nothing to do with text strings, there is the real problem that strings are not mutable, so direct manipulation of the data returned in these cases is not possible. Also, numerous optimizations in the string module (such as caching the hash value or interning the pointers) mean that extension authors are on very thin ice if ...
...string (unicode) "": native string (str) b"": binary data (str, also aliased as bytes) In Python 3, the latin-1 decoded native strings are not distinguished from any other text strings: "": text string (str) "": native string (str) b"": binary data (bytes) If from __future__ import unicode_literals is used to modify the behaviour of Python 2, then, along with an appropriate definition of n(), the distinction can be expressed as: "": text string n(""): native string b"": binary data (While n...
...string exceptions. Adoption of this proposal breaks backwards compatibility. Under the proposed implementation schedule, Python 2.4 will introduce warnings about uses of raise which will eventually become incorrect, and Python 3.0 will eliminate them entirely. (It is assumed that this transition period -- 2.4 to 3.0 -- will be at least one year long, to comply with the guidelines of PEP 5.) Motivation String Exceptions It is assumed that removing string exceptions will be uncontroversial, s...
...string if creationDate.endswith('\\n'): creationDate = creationDate[:-len('\\n')] Improved: creationDate = header['POT-Creation-Date'].removesuffix('\\n') There were many other such examples in the stdlib. Rejected Ideas Expand the lstrip and rstrip APIs Because lstrip takes a string as its argument, it could be viewed as taking an iterable of length-1 strings. The API could, therefore, be generalized to accept any iterable of strings, which would be successively removed as prefix...
...string of digits changes the meaning of that digit string entirely. It was pointed out during this discussion that a similar, but shorter, discussion on the subject occurred in January 2006, prompted by a discovery of the same issue. Background For historical reasons, Python's string representation of integers in different bases (radices), for string formatting and token literals, borrows heavily from C. [1] [2] Usage has shown that the historical method of specifying an octal number is confus...
...string to specify the byte order. Using (2) with UTF-16, results in an 8 bit string with a BOM between every character. To work around this problem, a stream writer - which keeps state between calls to the encoding function - has to be used: # (3) us = u"xxx" import codecs, cStringIO as StringIO writer = codecs.getwriter(encoding) v = StringIO.StringIO() uv = writer(v) for c in us: try: uv.write(c) except UnicodeError: uv.write(u"&#%d;" % ord(c)) s = v.getvalue() ...
...strings passed to fp.write() would be converted to use fp.newlines as their line terminator but all other output would not is far too surprising, in my view. Because there is no output support for universal newlines there is also no support for a mode "rU+": the surprise factor of the previous paragraph would hold to an even stronger degree. There is no support for universal newlines in strings passed to eval() or exec. It is envisioned that such strings always have the standard \n line feed, if...
...string representation corresponding to IEEE 754 positive infinity. Python 2.1.3 on x86 Debian Linux returns "inf". On Sparc Solaris 8 with Python 2.2.1, this same expression returns "Infinity", and on MS-Windows 2000 with Active Python 2.2.1, it returns "1.#INF". Adding to the confusion, some platforms generate one string on conversion from floating point and accept a different string for conversion to floating point. On these systems float(str(x)) will generate an error when "x" is an IEEE...
...string representation of the given datetime instance. The __datetime_strftime__ method should take a datetime instance and a format string and produce a string representation of the given datetime instance formatted according to the given format. Parsing A tzinfo subclass supporting the PDDM, may define a class method called __datetime_strptime__ and register the "canonical" names of the timezones that it implements with a registry. TODO Describe a registry. Changes to datetime methods Sub...
...string "10" supposed to be a string, a float or an int? is it a number in base 10, base 16 or base 2? is a number in quotes a number or a string?) locale-specific data representation (should the number 1.23 be written as "1.23" or "1,23" or "1 23"?) -- this may eventually be addressed. fixed width tabular data - can already be parsed reliably. Rationale Often, CSV files are formatted simply enough that you can get by reading them line-by-line and splitting on the commas which delimit the fiel...