From 4374506981139e4988d1d6b099b47b3344642ff7 Mon Sep 17 00:00:00 2001 From: cclauss Date: Wed, 15 Aug 2018 16:25:58 +0200 Subject: [PATCH] Define raw_input() in Python 3 & fix time.sleep() * __raw_input()__ was removed in Python 3 in favor of __input()__ * Fix __sleep()__ to match the import on line 22 [flake8](http://flake8.pycqa.org) testing of https://github.com/node-red/node-red on Python 3.7.0 $ __flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics__ ``` ./nodes/core/hardware/nrgpio.py:45:24: F821 undefined name 'raw_input' data = raw_input() ^ ./nodes/core/hardware/nrgpio.py:63:24: F821 undefined name 'raw_input' data = raw_input() ^ ./nodes/core/hardware/nrgpio.py:85:24: F821 undefined name 'raw_input' data = raw_input() ^ ./nodes/core/hardware/nrgpio.py:120:24: F821 undefined name 'raw_input' data = raw_input() ^ ./nodes/core/hardware/nrgpio.py:134:24: F821 undefined name 'raw_input' data = raw_input() ^ ./nodes/core/hardware/nrgpio.py:164:24: F821 undefined name 'raw_input' data = raw_input() ^ ./nodes/core/hardware/nrgpio.py:201:17: F821 undefined name 'time' time.sleep(10) ^ 7 F821 undefined name 'raw_input' 7 ``` @dceejay --- nodes/core/hardware/nrgpio.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nodes/core/hardware/nrgpio.py b/nodes/core/hardware/nrgpio.py index 0cde0e4df..7908ca117 100755 --- a/nodes/core/hardware/nrgpio.py +++ b/nodes/core/hardware/nrgpio.py @@ -21,7 +21,12 @@ import os import subprocess from time import sleep -bounce = 25; +try: + raw_input # Python 2 +except NameError: + raw_input = input # Python 3 + +bounce = 25 if len(sys.argv) > 2: cmd = sys.argv[1].lower() @@ -198,7 +203,7 @@ if len(sys.argv) > 2: elif cmd == "kbd": # catch keyboard button events try: while not os.path.isdir("/dev/input/by-path"): - time.sleep(10) + sleep(10) infile = subprocess.check_output("ls /dev/input/by-path/ | grep -m 1 'kbd'", shell=True).strip() infile_path = "/dev/input/by-path/" + infile EVENT_SIZE = struct.calcsize('llHHI')