Skip to content

Latest commit

 

History

History
42 lines (37 loc) · 5.59 KB

WhatsNewInPython31.md

File metadata and controls

42 lines (37 loc) · 5.59 KB

What's New In Python 3.1

https://docs.python.org/3/whatsnew/3.1.html

PEPs

  • PEP 372: Ordered Dictionaries
  • PEP 378: Format Specifier for Thousands Separator

Other Language Changes

  • Directories and zip archives containing a __main__.py file can now be executed directly by passing their name to the interpreter. The directory/zipfile is automatically inserted as the first entry in sys.path.
  • The int() type gained a bit_length method that returns the number of bits necessary to represent its argument in binary.
  • The fields in format() strings can now be automatically numbered.
  • The string.maketrans() function is deprecated and is replaced by new static methods, bytes.maketrans() and bytearray.maketrans(). This change solves the confusion around which types were supported by the string module. Now, str, bytes, and bytearray each have their own maketrans and translate methods with intermediate translation tables of the appropriate type.
  • The syntax of the with statement now allows multiple context managers in a single statement.
  • round(x, n) now returns an integer if x is an integer. Previously it returned a float.
  • Python now uses David Gay's algorithm for finding the shortest floating point representation that doesn't change its value.

New, Improved, and Deprecated Modules

  • Added a collections.Counter class to support convenient counting of unique items in a sequence or iterable.
  • Added a new module, tkinter.ttk for access to the Tk themed widget set. The basic idea of ttk is to separate, to the extent possible, the code implementing a widget's behavior from the code implementing its appearance.
  • The gzip.GzipFile and bz2.BZ2File classes now support the context management protocol.
  • The decimal module now supports methods for creating a decimal object from a binary float.
  • The itertools module grew two new functions. The itertools.combinations_with_replacement() function is one of four for generating combinatorics including permutations and Cartesian products. The itertools.compress() function mimics its namesake from APL. Also, the existing itertools.count() function now has an optional step argument and can accept any type of counting sequence including fractions.Fraction and decimal.Decimal.
  • collections.namedtuple() now supports a keyword argument rename which lets invalid fieldnames be automatically converted to positional names in the form _0, _1, etc. This is useful when the field names are being created by an external source such as a CSV header, SQL field list, or user input.
  • The re.sub(), re.subn() and re.split() functions now accept a flags parameter.
  • The logging module now implements a simple logging.NullHandler class for applications that are not using logging but are calling library code that does. Setting-up a null handler will suppress spurious warnings such as "No handlers could be found for logger foo".
  • The runpy module