From 7be92d78fc4a804326e4013a28d1741316998c53 Mon Sep 17 00:00:00 2001 From: Vu Cong Tuan Date: Thu, 5 Jul 2018 10:35:31 +0700 Subject: [PATCH] Replace file() with open() for Python 3 compatibility The built-in named 'file' has been removed since Python 3.0 [1] This patch replaces it by 'open' which is the same under Python 2 and 3. [1] https://docs.python.org/release/3.0/whatsnew/3.0.html#builtins Change-Id: Ib2abbd0f6aea4423acae0c7dceccf1ef67c1caae --- fm-common/sources/fm_db_sync_event_suppression.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fm-common/sources/fm_db_sync_event_suppression.py b/fm-common/sources/fm_db_sync_event_suppression.py index a859f6df..be8d78a3 100755 --- a/fm-common/sources/fm_db_sync_event_suppression.py +++ b/fm-common/sources/fm_db_sync_event_suppression.py @@ -105,15 +105,15 @@ EVENT_TYPES_FILE = get_events_yaml_filename() if not os.path.isfile(EVENT_TYPES_FILE): exit (-1) -stream = file(EVENT_TYPES_FILE, 'r') -event_types = yaml.load(stream) +with open(EVENT_TYPES_FILE, 'r') as stream: + event_types = yaml.load(stream) for alarm_id in event_types: if isinstance(alarm_id, float): # force 3 digits after the decimal point, # to include trailing zero's (ex.: 200.010) - formatted_alarm_id = "{:.3f}".format(alarm_id) - event_types[formatted_alarm_id] = event_types.pop(alarm_id) + formatted_alarm_id = "{:.3f}".format(alarm_id) + event_types[formatted_alarm_id] = event_types.pop(alarm_id) event_types = collections.OrderedDict(sorted(event_types.items()))