basically I use a software called Geany as my python editor.
I have python 3 installed on my computer
I have a linting package installed in Geany.
I fix all the linting errors. Which will fix a lot of python 3 errors.
Then I will load the plugin onto box, try everything and see what crashes. Then google for the answers. Which will normally direct you to a similar question on stackoverflow.
The rest just comes through experience of what works in python 2 and python 3. I code to work in both though. So I use conditionals.
Its always the same errors over and over again.
Usually different library or module calls that might have changed between versions.
But generally all print statements need to be in brackets. print("BLAHBLAH"). This is often the major culprit. All old plugins would have wrote print "BLAHBLAH"
python 3 handles strings differently. So might need wrapping in a str() or sometimes a .decode() or .encode() is required.
This is the most confusing aspect. python 3 is bytes for everything. python 2 classes everything as a string. It doesn't care.
here are some conditionals I have in my various plugins. Which highlights some changes needed to run in both.
import sys
pythonVer = 2
if sys.version_info.major == 3:
pythonVer = 3
if pythonVer == 2:
from urllib2 import urlopen, Request
else:
from urllib.request import urlopen, Request
if pythonVer == 2:
from urllib import quote
else:
from urllib.parse import quote
from a file load
for line in lines:
if pythonVer == 3:
line = line.decode()
from a url response
for line in response:
if pythonVer == 3:
try:
line = line.decode("utf-8")
except:
pass
timestamp example
if pythonVer == 2:
glob.pintime = int(time.mktime(datetime.now().timetuple()))
else:
glob.pintime = int(datetime.timestamp(datetime.now()))
simple byte to string conversion
if pythonVer == 3:
data = str(data)
Basically all the above will pretty much get most plugins working
Make sure the library calls are correct
Make sure all print statements are in brackets.
Make sure strings are specifically converted to strings. If a string is required.
It is not always that simple. But most plugins are not really over complicated. They might read a file. They might download from a url. Display a few results.