From 73d2f952a43207965bbc2345d6381a6661ceeee5 Mon Sep 17 00:00:00 2001 From: Stephen L Date: Sat, 27 Jan 2018 20:49:14 +0100 Subject: [PATCH] Various fixes for Python 2 compatibility Signed-off-by: Stephen L. --- niwidgets/exampledata.py | 2 +- niwidgets/niwidget_surface.py | 2 +- niwidgets/niwidget_volume.py | 9 ++++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/niwidgets/exampledata.py b/niwidgets/exampledata.py index 367ac3e..453069b 100644 --- a/niwidgets/exampledata.py +++ b/niwidgets/exampledata.py @@ -3,7 +3,7 @@ try: # on >3 this ships by default from pathlib import Path -except ModuleNotFoundError: +except ImportError: # on 2.7 this should work try: from pathlib2 import Path diff --git a/niwidgets/niwidget_surface.py b/niwidgets/niwidget_surface.py index 26312db..ce9a3aa 100644 --- a/niwidgets/niwidget_surface.py +++ b/niwidgets/niwidget_surface.py @@ -12,7 +12,7 @@ try: # on >3 this ships by default from pathlib import Path -except ModuleNotFoundError: +except ImportError: # on 2.7 this should work try: from pathlib2 import Path diff --git a/niwidgets/niwidget_volume.py b/niwidgets/niwidget_volume.py index 462024f..fa31ecd 100644 --- a/niwidgets/niwidget_volume.py +++ b/niwidgets/niwidget_volume.py @@ -10,13 +10,13 @@ try: # on >3 this ships by default from pathlib import Path -except ModuleNotFoundError: +except ImportError: # on 2.7 this should work try: from pathlib2 import Path - except ModuleNotFoundError: - raise ModuleNotFoundError('On python 2.7, niwidgets requires ' - 'pathlib2 to be installed.') + except ImportError: + raise ImportError('On python 2.7, niwidgets requires ' + 'pathlib2 to be installed.') class NiftiWidget: @@ -43,7 +43,6 @@ def __init__(self, filename): if hasattr(filename, 'get_data'): self.data = filename else: - filename = Path(filename).resolve() if not filename.is_file(): raise OSError('File ' + filename.name + ' not found.')