Hi guys.
Conversion from PY2 to PY3 for the Enigma2 environment is very simple.
The problem is that there are an awful lot of files. The plugin is assembled from a "million" parts, and each file needs to be opened individually and check its functionality (run the PY3 code).
There are also conversion applications that convert the code from PY2 to PY3, but they are universal. This means that there will not be added many necessary things that apply in the case of Enigma2 set-top boxes. If it were only one single Python file, or 3-5 files, I can do it. But since there are a lot of files, it is difficult to convert them and test them at the same time. And without testing, I don't want to transfer it from PY2 to PY3... there must be 100% certainty in functionality.
First of all, the most common problem is, for example, using print as a function and not as a built-in command of the Python interpreter. In the new PY3, print is used as a function. So the syntax changed to the necessary parentheses:
print("hello world")
As for backward compatibility with PY2 with the print function, it is necessary to make this import (I don't know from which version of PY2 specifically, this was added):
from __future__ import print_function
But this is not always necessary.
The second common problem I see when converting from PY2 to PY3 on the Enigma2 platform is incorrect syntax of the "try" command. When using exceptions:
except Exception as err:
instead of the original
except Exception, err:
Another frequent problem is string data type, because in PY2 and PY3 there are some differences ( https://portingguide.readthedocs.io/en/latest/strings.html ). For example:
PY2 console:
>>> s = u"test"
>>> type(s)
<type 'unicode'>
PY3 console:
>>> s = u"test"
>>> type(s)
<class 'str'>
Another common problem is the urllib2 module in PY2, which no longer exists in PY3 (it was replaced / merged with other modules into one). Usually (not always) a simple replacement of it + renaming the imported module in PY3 will help, like this:
import sys
if sys.version_info.major == 3: # sys.version_info(major=3, minor=10, micro=1, releaselevel='final', serial=0)
import urllib.request as urllib2
else:
import urllib2
And of course a few other details have also changed (I don't remember exactly, but when I refactor the code, I would remember, haha). For example, a different style is now used in PY3 to access the dictionary data type when using keys, in some specific cases (this is to make accessing the dictionary data type clearer and cleaner).