summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbryan newbold <bnewbold@twinleaf.com>2015-04-06 10:12:33 -0700
committerbryan newbold <bnewbold@twinleaf.com>2015-04-06 10:14:30 -0700
commitf027925deef57d0d7a3768642cb616b4c541a94d (patch)
treeb7054506a4c47953d93c60da7e70c31e7b559fbd
parentc61bf6be45c087c9083601662de8c37dfd061130 (diff)
downloadknowledge-f027925deef57d0d7a3768642cb616b4c541a94d.tar.gz
knowledge-f027925deef57d0d7a3768642cb616b4c541a94d.zip
python: python3 porting
-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.