Differences between revisions 5 and 29 (spanning 24 versions)
Revision 5 as of 2006-02-20 23:09:49
Size: 2566
Editor: 60
Comment: spelling mistake Excption -> Exception in exception section
Revision 29 as of 2019-10-19 22:14:19
Size: 890
Comment: Remove Python 2 information, leaving a link to previous revision for accessibility
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Python is a mature language, but it hasn't stopped evolving,
and there are some issues to consider when coding Python, if
you want your code to work with the latest version of Python
in five five years from now... See
http://www.python.org/peps/pep-3000.html for more
information.
Line 8: Line 2:
= True Division = The future of [[http://www.python.org/peps/pep-3000.html|Python 3000]] is now! As of January 2020 Python 2 will be in EOL (End Of Life) status and receive no further official support. After that date, there will be no further updates nor bugfixes. Since this end-of-life date has been planned for nearly a decade (the first end-of-life date was slated to happen in 2014, and was pushed back to 2020), and nearly all popular libraries have already ported their code, Python 2.x is well on its way out.
Line 10: Line 4:
Since the beginning, Python has yielded an integer result when
two integers are divided, e.g. 3/2 => 1. While correct if we
assume that dividing integers means integer division (the
remainder is accessible through the modulo operator %) it's
not always obvious to beginners. This behaviour will change in
a future Python version, so that a/b with yield a float as a
result regardless of the types of the numbers a and b, and
a new floor division operator // will perform integer
division. See See http://www.python.org/peps/pep-0238.html
[[https://wiki.python.org/moin/FutureProofPython?action=recall&rev=28|Previous page revisions]] have historical information that may be useful in porting or maintaining remaining Python 2 systems.
If you need additional support in porting existing 2.x code to 3.x, please see the resources available for [[PortingPythonToPy3k|porting Python 2 code]].
Line 20: Line 7:
    '''Use true and floor division in new code'''

{{{
from __future__ import division # Enable the new behaviour

f = 3/2 # 1.5

i = 3//2 # 1
}}}


= New style classes =

Currently, there are two kinds of classes in Python. The 'classic'
or old style classes, and the new style classes. Old style classes
will go away in some future version, and while most code will still
work when the default swaps from old style to new style, there are
some differences in semantics, and the new style classes have some
extra features. See http://www.python.org/doc/newstyle.html

    '''Use new style classes in new code'''

Don't write
{{{
class X:
    pass
}}}

Write
{{{
class X(object):
    pass
}}}


= Let all exception classes inherit from Exception =

From Python 3.0, all exceptions must be derived from Base''''''Exception,
which will be the base class for Keyboard''''''Interrupt, System''''''Exit and
Exception from Python 2.5. See http://www.python.org/peps/pep-0352.html


    '''When defining new exception classes, always inherit (directly or indirectly) from Exception'''

{{{
class MyException(Exception): pass
}}}

= Use parenthesis for Exception argument =

The syntax
{{{
raise MyException "A nasty error"
}}}
will be deprecated. Use
{{{
raise MyException("A nasty error")
}}}
instead.

= Don't compare uncomparable objects =

In the future, x < y and friends (>, <=, >=) will raise an exception instead
of an arbitrary result, if type(x) != type(y) unless the types explicitly
define the behaviour for these comparisions.

= Don't use <> =

It's enough with one inequality operator. Almost everybody uses !=. <> will go away.
----
CategoryDocumentation

The future of Python 3000 is now! As of January 2020 Python 2 will be in EOL (End Of Life) status and receive no further official support. After that date, there will be no further updates nor bugfixes. Since this end-of-life date has been planned for nearly a decade (the first end-of-life date was slated to happen in 2014, and was pushed back to 2020), and nearly all popular libraries have already ported their code, Python 2.x is well on its way out.

Previous page revisions have historical information that may be useful in porting or maintaining remaining Python 2 systems. If you need additional support in porting existing 2.x code to 3.x, please see the resources available for porting Python 2 code.


CategoryDocumentation

FutureProofPython (last edited 2019-10-19 22:14:19 by FrancesHocutt)

Unable to edit the page? See the FrontPage for instructions.