2 + 3 - 6

Why?

How? (non-code bits)

  1. Give up on compatibility with Python < 2.6
  2. It's not horribly unreasonable (2.6 or above is now default on most common platforms)

How? (code bits)

  1. Add a full complement of from __future__ imports to all your modules
  2. Make all strings compatible (u'' to '')
  3. Make all print statements functions (print '' to print(''))
  4. Make all relative imports absolute (you were using relative imports? Tut tut)
  5. Grep for any division operators and check their type

Example

from __future__ import (
    unicode_literals,
    print_function,
    absolute_import,
    division,
    )

from rastools.raspase import RasParser
# ^--- absolute import

print('Some stuff')
# ^--- using print function

What Next?

Stuff you'll probably find

Example

from PIL import Image
try:
    # XXX Py2 only
    from cStringIO import StringIO
except ImportError:
    # XXX Py2 only
    from StringIO import StringIO
except ImportError:
    # XXX Py3 only
    from io import StringIO

More Examples!

try:
    self._file = open(filename_or_obj, 'w')
except TypeError:
    self._file = filename_or_obj

Instead of:

if isinstance(filename_or_obj, basestring):
    self._file = open(filename_or_obj, 'w')
else:
    self._file = filename_or_obj

Packaging

Conclusion

/

#