diff --git a/porting-code-to-python-3-with-2to3.html b/porting-code-to-python-3-with-2to3.html index 80ffa84..82a0106 100644 --- a/porting-code-to-python-3-with-2to3.html +++ b/porting-code-to-python-3-with-2to3.html @@ -342,7 +342,7 @@ except ImportError:
  • The queue module implements a multi-producer, multi-consumer queue.
  • The socketserver module provides generic base classes for implementing different kinds of socket servers.
  • The configparser module parses INI-style configuration files. -
  • The reprlib module reimplements the built-in repr() function, but with limits on how many values are represented. +
  • The reprlib module reimplements the built-in repr() function, with additional controls on how long the representations can be before they are truncated.
  • The subprocess module allows you to spawn processes, connect to their pipes, and obtain their return codes.

    Relative imports within a package

    @@ -793,7 +793,7 @@ except:
  • You can define lambda functions that take multiple arguments. Without parentheses around the arguments, Python 2 just treats it as a lambda function with multiple arguments; within the lambda function, you simply reference the arguments by name, just like any other function. This syntax still works in Python 3.

    Special method attributes

    -

    In Python 2, class methods can reference the class object they are defined in, as well as the method object itself. im_self is the class instance object; the class im_func is the function object; im_class is the class of im_self (for bound methods) or the class that asked for the method (for unbound methods). In Python 3, these special method attributes have been renamed to follow the naming conventions of other attributes. +

    In Python 2, class methods can reference the class object in which they are defined, as well as the method object itself. im_self is the class instance object; im_func is the function object; im_class is the class of im_self. In Python 3, these special method attributes have been renamed to follow the naming conventions of other attributes.
    Notes Python 2 @@ -806,7 +806,7 @@ except: aClassInstance.aClassMethod.__self__
    aClassInstance.aClassMethod.im_class -aClassInstance.aClassMethod.self.__class__ +aClassInstance.aClassMethod.__self__.__class__

    __nonzero__ special method

    In Python 2, you could build your own classes that could be used in a boolean context. For example, you could instantiate the class and then use the instance in an if statement. To do this, you defined a special __nonzero__() method which returned True or False, and it was called whenever the instance was used in a boolean context. In Python 3, you can still do this, but the name of the method has changed to __bool__(). @@ -1059,7 +1059,7 @@ except: {i for i in a_sequence}

    buffer() global function (explicit)

    -

    Python objects implemented in C can export a “buffer interface,” which is a block of memory that is directly readable and writeable without copying. (That is exactly as powerful and scary as it sounds.) In Python 3, buffer() has been renamed to memoryview(). (It’s a little more complicated than that, but you can almost certainly ignore the differences.) +

    Python objects implemented in C can export a “buffer interface,” which allows other Python code to directly read and write a block of memory. (That is exactly as powerful and scary as it sounds.) In Python 3, buffer() has been renamed to memoryview(). (It’s a little more complicated than that, but you can almost certainly ignore the differences.)

    The 2to3 script will not fix the buffer() function by default. To enable this fix, specify -f buffer on the command line when you call 2to3.