Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Allows the function version of the print statements to be used.
  2. Gives us a value (USING_PYTHON2) that can be tested for at run time to determine if we are running Python2 or Python3.

Import Statements

Changing the #ifndef/#else/#endif Statements

You need to The way that imports of functions found in local files changes in Python3. So change blocks such as this:

#ifndef USING_PYTHON2

from logginginterface import *

some python2 code

#else /* USING_PYTHON2 */

from .logginginterface import *

some python3 code

#endif /* USING_PYTHON2 */

to this. Make CERTAIN that the indentation is adjusted as well.

if USING_PYTHON2:

 

from logginginterface import *

some python2 code

else:

 

from .logginginterface import *

some python3 code

Yes, there is some cognitive dissonance for changing "#ifndef" to "if", but the rest of the generated code is set up properly to be able to quickly edit the code.

  • Search for all instances of "#ifndef USING_PYTHON2" and change "#ifndef" to "if" and add a trailing ":".
  • Search for all instances of "#else /* USING_PYTHON2 */" and change that to "else:".
  • Remove all instances of "#endif /* USING_PYTHON2 */" from the code.
  • Re-indent the lines in between.

Import Statements

The way that imports of functions found in local files changes in Python3. So change blocks such as this:

#ifndef USING_PYTHON2

from logginginterface import *

#else /* USING_PYTHON2 */

from .logginginterface import *

#endif /* USING_PYTHON2 */

to this. Make CERTAIN that the indentation is adjusted as well.

if USING_PYTHON2:

  from logginginterface import *

else:

  from .logginginterface import *

In some cases, standard library interfaces have changed. So change blocks such as this:

...