diff --git a/bindings/python/unicorn/unicorn.py b/bindings/python/unicorn/unicorn.py index 3ad3cb37..46effdcf 100644 --- a/bindings/python/unicorn/unicorn.py +++ b/bindings/python/unicorn/unicorn.py @@ -8,7 +8,7 @@ from .unicorn_const import ( __version__ = "%u.%u.%u" % (__MAJOR, __MINOR, __PATCH) -if _sys.version_info.major == 2: - from .unicorn_py2 import * -else: +if _sys.version_info >= (3,): from .unicorn_py3 import * +else: + from .unicorn_py2 import * diff --git a/bindings/python/unicorn/unicorn_py2.py b/bindings/python/unicorn/unicorn_py2.py index cc5450f0..a7db13db 100644 --- a/bindings/python/unicorn/unicorn_py2.py +++ b/bindings/python/unicorn/unicorn_py2.py @@ -23,8 +23,7 @@ ucsubclass = 0 if not hasattr(sys.modules[__name__], "__file__"): __file__ = inspect.getfile(inspect.currentframe()) -_python2 = sys.version_info[0] < 3 -if _python2: +if sys.version_info < (3,): range = xrange _lib = { 'darwin': 'libunicorn.2.dylib', @@ -55,7 +54,7 @@ def _load_win_support(path): ctypes.cdll.LoadLibrary(lib_file) #print('SUCCESS') _loaded_windows_dlls.add(dll) - except OSError as e: + except OSError: #print('FAIL to load %s' %lib_file, e) continue @@ -72,7 +71,7 @@ def _load_lib(path): dll = ctypes.cdll.LoadLibrary(lib_file) #print('SUCCESS') return dll - except OSError as e: + except OSError: #print('FAIL to load %s' %lib_file, e) return None diff --git a/bindings/python/unicorn/unicorn_py3/unicorn.py b/bindings/python/unicorn/unicorn_py3/unicorn.py index 5e747005..56237d3b 100644 --- a/bindings/python/unicorn/unicorn_py3/unicorn.py +++ b/bindings/python/unicorn/unicorn_py3/unicorn.py @@ -104,7 +104,7 @@ def __load_uc_lib() -> ctypes.CDLL: # - global load # - python's lib directory - if sys.version_info.minor >= 12: + if sys.version_info >= (3, 12): from importlib import resources canonicals = resources.files('unicorn') / 'lib' diff --git a/tests/regress/init.py b/tests/regress/init.py index a7391ccb..6ab4a682 100755 --- a/tests/regress/init.py +++ b/tests/regress/init.py @@ -9,7 +9,7 @@ from unicorn import * from unicorn.x86_const import * -if sys.version_info.major == 2: +if sys.version_info < (3,): range = xrange