How old is python 2.6
At some point Python 3. The buffer protocol is a C-level API that lets Python types exchange pointers into their internal representations.
A memory-mapped file can be viewed as a buffer of characters, for example, and this lets another module such as re treat memory-mapped files as a string of characters to be searched. The primary users of the buffer protocol are numeric-processing packages such as NumPy, which expose the internal representation of arrays so that callers can write data directly into an array instead of going through a slower API.
This PEP updates the buffer protocol in light of experience from NumPy development, adding a number of new features such as indicating the shape of an array or locking a memory region. Some examples are:.
Some object-oriented languages such as Java support interfaces, declaring that a class has a given set of methods or supports a given access protocol. The ABC support consists of an abc module containing a metaclass called ABCMeta , special handling of this metaclass by the isinstance and issubclass builtins, and a collection of basic ABCs that the Python developers think will be widely useful.
Future versions of Python will probably add more ABCs. It probably means that accessing items with obj[1] works. Or that the object will have keys , values , and items methods?
What about the iterative variants such as iterkeys? Iterating over the object with iter? The Python 2. The basic dictionary interface of getting items, setting items, and keys , values , and items , is defined by the MutableMapping ABC. For classes that you write, deriving from the ABC is probably clearer. You can write your own ABCs by using abc. ABCMeta as the metaclass in a class definition:. Note that the exception is only raised when you actually try to create an instance of a subclass lacking the method:.
Abstract data attributes can be declared using the abstractproperty decorator:. Subclasses must then define a readonly property. The oct builtin still returns numbers prefixed with a leading zero, and a new bin builtin returns the binary representation for a number:. These classes were backported to 2. The most general ABC is Number. It defines no operations at all, and only exists to allow checking if an object is a number by doing isinstance obj, Number.
Complex is a subclass of Number. Real further derives from Complex , and adds operations that only work on real numbers: floor , trunc , rounding, taking the remainder mod N, floor division, and comparisons.
Rational numbers derive from Real , have numerator and denominator properties, and can be converted to floats. To fill out the hierarchy of numeric types, the fractions module provides a rational-number class. The Fraction constructor takes two Integral values that will be the numerator and denominator of the resulting fraction. Note that values that can only be approximated by floating-point numbers, such as 1. This implementation was significantly updated by Jeffrey Yasskin. The directory or zip archive is automatically inserted as the first entry in sys.
Suggestion and initial patch by Andy Chu, subsequently revised by Phillip J. Eby and Nick Coghlan; issue Fixed by Benjamin Peterson; issue Contributed by Alexander Belopolsky; issue Previously this would have been a syntax error. A new builtin, next iterator, [default] returns the next item from the specified iterator. If the default argument is supplied, it will be returned if iterator has been exhausted; otherwise, the StopIteration exception will be raised.
Backported in issue The built-in types now have improved support for extended slicing syntax, accepting various combinations of start, stop, step.
Implemented by Thomas Wouters. Properties now have three attributes, getter , setter and deleter , that are decorators providing useful shortcuts for adding a getter, setter or deleter function to an existing property.
You would use them like this:. Many floating-point features were added. This works on any platform with IEEE semantics. Contributed by Christian Heimes; issue Other functions in the math module, isinf and isnan , return true if their floating-point argument is infinite or Not A Number.
Conversion functions were added to convert floating-point numbers into hexadecimal strings issue These functions convert floats to and from a string representation without introducing rounding errors from the conversion between decimal and binary.
Floats have a hex method that returns a string representation, and the float. Fixed by Mark T. Dickinson; issue All objects have a default hash method that uses id obj as the hash value. This means that an exception handler that does except Exception: will not inadvertently catch GeneratorExit. Contributed by Chad Austin; issue Contributed by Collin Winter; issue The compile built-in function now accepts keyword arguments as well as positional parameters.
Contributed by Thomas Wouters; issue The complex constructor now accepts strings containing parenthesized complex numbers, meaning that complex repr cplx will now round-trip values.
The string translate method now accepts None as the translation table parameter, which is treated as the identity transformation. This makes it easier to carry out operations that only delete characters.
Contributed by Bengt Richter and implemented by Raymond Hettinger; issue This method must return a list of strings containing the names of valid attributes for the object, and lets the object control the value that dir produces. The old names are still supported in Python 2. An obscure change: when you use the locals function inside a class statement, the resulting dictionary no longer returns free variables.
The warnings module has been rewritten in C. Contributed by Neal Norwitz and Brett Cannon; issue Original optimization implemented by Armin Rigo, updated for Python 2. By default, this change is only applied to types that are included with the Python core. See issue for some discussion. Function calls that use keyword arguments are significantly faster by doing a quick pointer comparison, usually saving the time of a full string comparison. Contributed by Raymond Hettinger, after an initial implementation by Antoine Pitrou; issue All of the functions in the struct module have been rewritten in C, thanks to work at the Need For Speed sprint.
Contributed by Raymond Hettinger. Some of the standard built-in types now set a bit in their type objects. This speeds up checking whether an object is a subclass of one of these types. Contributed by Neal Norwitz. Contributed by Antoine Pitrou. Implemented by Jeffrey Yasskin.
To reduce memory usage, the garbage collector will now clear internal free lists when garbage-collecting the highest generation of objects. This may return memory to the operating system sooner.
Two command-line options have been reserved for use by other Python implementations. The -J switch has been reserved for use by Jython for Jython-specific options, such as switches that are passed to the underlying JVM.
If either option is used with Python 2. Python can now be prevented from writing. This setting is available to Python programs as the sys.
Contributed by Neal Norwitz and Georg Brandl. Contributed by Martin von Loewis. The asyncore and asynchat modules are being actively maintained again, and a number of patches and bugfixes were applied. Maintained by Josiah Carlson; see issue for one patch. The web page for the package is www. The plan is to remove the package from the standard library in Python 3.
The bsddb. Contributed by W. Contributed by Alexandre Fiori and Nubis; issue The versions still available in the cgi module will trigger PendingDeprecationWarning messages in 2. The cmath module underwent extensive revision, contributed by Mark Dickinson and Christian Heimes.
Five new functions were added:. The revisions also improved the numerical soundness of the cmath module. For all functions, the real and imaginary parts of the results are accurate to within a few units of least precision ulps whenever possible. See issue for the details. The branch cuts for asinh , atanh : and atan have also been corrected. The tests for the module have been greatly expanded; nearly new test cases exercise the algebraic functions.
A new data type in the collections module: namedtuple typename, fieldnames is a factory function that creates subclasses of the standard tuple whose fields are accessible by name as well as index.
Several places in the standard library that returned tuples have been modified to return namedtuple instances. For example, the Decimal. Adding more items to a full deque causes old items to be discarded. In some browsers.
Contributed by Arvin Schnell; issue A new window method in the curses module, chgat , changes the display attributes for a certain number of characters on a single line. Contributed by Fabian Kreutz. The Textbox class in the curses. Contributed by Skip Montanaro; issue The decimal module was updated to version 1. New features include some methods for some basic mathematical functions such as exp and log10 :.
Implemented by Facundo Batista and Mark Dickinson. Named tuple support added by Raymond Hettinger. An optional timeout parameter, specifying a timeout measured in seconds, was added to the ftplib. FTP class constructor as well as the connect method. Added by Facundo Batista. Contributed by Phil Schwartz; issue The reduce built-in function is also available in the functools module. Patched by Christian Heimes; issue If the password may be echoed to the terminal, a warning is printed before the prompt is displayed.
Contributed by Gregory P. The glob. A new function in the heapq module, merge iter1, iter2, Another new function, heappushpop heap, item , pushes item onto heap , then pops off and returns the smallest item. This is more efficient than making a call to heappush and then heappop. An optional timeout parameter, specifying a timeout measured in seconds, was added to the httplib.
In addition to behaving like tuples, the elements of the return value can also be accessed as attributes. Some new functions in the module include isgenerator , isgeneratorfunction , and isabstract. The itertools module gained several new functions. The optional repeat keyword argument is used for taking the product of an iterable or a set of iterables with themselves, repeated N times. With a single iterable argument, N -tuples are returned:. If r is not specified, it will default to the number of elements produced by the iterable.
If delay is true, opening of the log file is deferred until the first emit call is made. Contributed by Vinay Sajip. TimedRotatingFileHandler also has a utc constructor parameter. If the argument is true, UTC time will be used in determining when midnight occurs and in generating filenames; otherwise local time will be used. Several new functions were added to the math module:. The math module has been improved to give more consistent behaviour across platforms, especially with respect to handling of floating-point exceptions and IEEE special values.
For example, sqrt See issue and issue The find method also gained an end parameter giving an index at which to stop searching.
Contributed by John Lenton. The operator module gained a methodcaller function that takes a name and an optional set of arguments, returning a callable that will call the named function on any arguments passed to it. The attrgetter function now accepts dotted names and performs the corresponding attribute lookups:. The os module now wraps several new system calls. Contributed by Georg Brandl and Christian Heimes.
Contributed by M. This function is now used by the subprocess module to make starting processes faster. Contributed by Georg Brandl; issue The os. Contributed by Martin Horcicka; issue In the os.
For example, os. A new function, os. Although, Python 2 is an old open source version here are where you still need to learn Python When it comes to Python 2 vs Python 3 differences today, Python 3 version is the outright winner. Mass Python 3 adoption is the clear direction of the future. After considering declining support for Python 2 programming language and added benefits from upgrades to Python 3, it is always advisable for a new developer to select Python version 3.
However, if a job demands Python 2 capabilities, that would be an only compelling reason to use this version. Skip to content. What is Python 2? What is Python 3? Python 3 exceptions should be enclosed in parenthesis while Python 2 exceptions should be enclosed in notations. Python 3 rules of ordering comparisons are simplified whereas Python 2 rules of ordering comparison are complex. If you're using Python 2.
You're running software that is not being maintained for security or bugfixes and so you should consider upgrading for those reasons alone.
Switching to Python 2. But one of the key reasons I'm asking you to upgrade to Python 2. There are plenty of projects out there that are run by people who do everything they can to support their users, including supporting outdated versions of Python.
That means they won't consider dropping support for Python 2. That leads to those projects not getting to use the newer features in Python 2. They also have to work around bugs in Python 2. Please realize that if you are using Python 2. And this won't necessarily stop at your direct dependencies either, as those dependencies will then need to ask their dependencies to support Python 2.
0コメント