From e4af62e51d061e5a146f6e557e3839f0f24c76ed Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 24 Mar 2022 15:45:40 +0100 Subject: [PATCH] Simu: Python's import system is too hard for me --- simulations/lib/location/antenna.py | 5 +---- simulations/lib/location/example.py | 10 ++++++++-- simulations/lib/signals/digitisedsignal.py | 10 ++++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/simulations/lib/location/antenna.py b/simulations/lib/location/antenna.py index 824eccc..6760345 100644 --- a/simulations/lib/location/antenna.py +++ b/simulations/lib/location/antenna.py @@ -1,9 +1,6 @@ from functools import partial -try: - from .location import Location -except ImportError: - from location import Location +from .location import Location class Antenna(Location): """ diff --git a/simulations/lib/location/example.py b/simulations/lib/location/example.py index 45b485b..9f37de6 100755 --- a/simulations/lib/location/example.py +++ b/simulations/lib/location/example.py @@ -3,8 +3,14 @@ import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import axes3d -import location as loc -from antenna import Receiver, Emitter +# fix package-internal importing +if __name__ == "__main__" and __package__ is None: + import sys + sys.path.append("../../") + __package__ = "lib.location" + +from . import location as loc +from ..location.antenna import Receiver, Emitter # 2D showcase source = Emitter([1,1]) diff --git a/simulations/lib/signals/digitisedsignal.py b/simulations/lib/signals/digitisedsignal.py index 5d2a09c..59d683d 100755 --- a/simulations/lib/signals/digitisedsignal.py +++ b/simulations/lib/signals/digitisedsignal.py @@ -2,10 +2,12 @@ import numpy as np import scipy.interpolate as interp -try: - from .signal import * -except ImportError: - from signal import * +if __name__ == "__main__" and __package__ is None: + import sys + sys.path.append("../../") + __package__ = "lib.signals" + +from .signal import * class DigitisedSignal(Signal): """