TM Wrestling With Python [Dramatized]
I decided to port everything to Python3 before starting the Raspbian image rebuild (so I only have to concentrate on one set of Python libraries). Thankfully, it took next to no time - a sad reflection on the lack of ambition in my Python coding.
sysinfo
Apart from adding brackets to print statements the only change required was to decode the output of subprocess.check_output() calls:
eg_string = subprocess.check_output("<shell commands>", shell=True).decode('utf-8').replace('\"', '')
Interestingly, I only needed to decode() calls with shell=True.
I also added a signature line to the top of the source (sysinfo.py),
#!/usr/bin/env python3
and changed the systemd service file (sysinfo.service) to use python3.
ExecStart=/usr/bin/python3 /home/pi/Python/sysinfo/sysinfo.py
Blinkter
dict_keys() and dict_values() return "views" instead of lists in Python3, so I had to change the already ugly line:
pattern_index = PATTERN_NAMES.keys()[PATTERN_NAMES.values().index(request.form['pattern_name'])]
to the shameful:
pattern_index = list(PATTERN_NAMES.keys())[list(PATTERN_NAMES.values()).index(request.form['pattern_name'])]
Maybe closer to the truth.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.