pearu / pylibnidaqmx

a Python wrapper to libnidaqmx library
Other
10 stars 9 forks source link

Python2/Python3 compatibility #72

Closed olsonse closed 5 years ago

olsonse commented 5 years ago

This patch must be applied on top of #71 (still pending as of this submission--there is actually just one commit here that is not included in #71). Much of this work is very similar to that done by @fgoettfert on the port_to_py3_testStage branch. In some cases, these changes are simpler, in others, these changes are specifically made to also support Py2 instead of just Py3.

Some testing has been done for Py2 and Py3.

From the log message of this patch:

This patch changes interactions between the c-library to use
.encode/.decode when using strings.  This is necessary for Python3 and
should generally be compatible for Python2.

This patch also changes the DAQmxConstants class to not be a namedtuple,
but rather a (mostly) immutable dict specialization.  This was necessary
because many versions of Python limit the number of function arguments to
255.  This change keeps DAQmx.* items (mostly) immutable and also
accessible using a pattern like DAQmx.value (rather than DAQmx['value']).

Otherwise, this patch changes print statements and includes more
'from __future__ import print_function' statements.  This patch also uses
the six.moves module to import input(py3)/raw_input(py2) appropriately for
some of the examples to ensure compatibility between Python2 and Python3.
The six module is not used for the main library.

This patch did _not_ need to do anything with respect to changing division
operations, since that had been done with earlier commits.

This patch does _not_ do anything to the packaging scripts or
documentation; this is expected to be done at a later date.