From 7d71f6641fcb660de0f003e2c028b464d7116ca1 Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Sat, 26 Jan 2019 09:19:22 +0000 Subject: python: Make iterator handling Python 3 compatible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Many functions that used to return lists (e.g., dict.items()) now return iterators and their iterator counterparts (e.g., dict.iteritems()) have been removed. Switch calls to the Python 2.7 iterator methods to use the Python 3 equivalent and add explicit list conversions where necessary. Change-Id: I0c18114955af8f4932d81fb689a0adb939dafaba Signed-off-by: Andreas Sandberg Reviewed-on: https://gem5-review.googlesource.com/c/15992 Reviewed-by: Juha Jäykkä Reviewed-by: Jason Lowe-Power --- src/python/m5/util/multidict.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'src/python/m5/util/multidict.py') diff --git a/src/python/m5/util/multidict.py b/src/python/m5/util/multidict.py index 5cc13eefa..23301565e 100644 --- a/src/python/m5/util/multidict.py +++ b/src/python/m5/util/multidict.py @@ -82,27 +82,18 @@ class multidict(object): def has_key(self, key): return key in self - def iteritems(self): + def items(self): for item in self.next(): yield item - def items(self): - return [ item for item in self.next() ] - - def iterkeys(self): + def keys(self): for key,value in self.next(): yield key - def keys(self): - return [ key for key,value in self.next() ] - - def itervalues(self): + def values(self): for key,value in self.next(): yield value - def values(self): - return [ value for key,value in self.next() ] - def get(self, key, default=None): try: return self[key] @@ -152,8 +143,8 @@ if __name__ == '__main__': test2.setdefault('f', multidict) - print('test1>', test1.items()) - print('test2>', test2.items()) + print('test1>', list(test1.items())) + print('test2>', list(test2.items())) #print(test1['a']) print(test1['b']) print(test1['c']) @@ -166,7 +157,7 @@ if __name__ == '__main__': print(test2['d']) print(test2['e']) - for key in test2.iterkeys(): + for key in test2.keys(): print(key) test2.get('g', 'foo') -- cgit v1.2.3