summaryrefslogtreecommitdiffstats
path: root/software
diff options
context:
space:
mode:
Diffstat (limited to 'software')
-rw-r--r--software/python.page20
1 files changed, 20 insertions, 0 deletions
diff --git a/software/python.page b/software/python.page
index b0a01e0..bcbf499 100644
--- a/software/python.page
+++ b/software/python.page
@@ -126,4 +126,24 @@ or in-line, always at a particular point:
Use ipdb (debian: python-ipdb) instead of pdb to get a nicer IPython prompt.
+Python 3 Porting
+-------------------
+
+To help port and support both Python 2.7 and 3.0+, start with an import::
+
+ from __future__ import absolute_import, division, print_function
+
+str/bytes/unicode is indeed the major porting challenge. Using bytearrays
+helps. Use ``b'asdf'`` style byte array definitions for most low-level
+constants.
+
+``struct.unpack()`` wants doesn't allow ``bytearray()``; use ``bytes()``
+instead.
+
+Make sure ``rase Exception ("Message here")`` style is used everywhere, instead
+of ``raise Exception, "Message here"``.
+
+There was some change in comparison between None and integers, which makes
+``if args.verbose > 0`` break. Use ``if args.verbose and args.verbose > 1``
+instead.