diff options
author | Andreas Sandberg <andreas.sandberg@arm.com> | 2019-01-26 09:19:22 +0000 |
---|---|---|
committer | Andreas Sandberg <andreas.sandberg@arm.com> | 2019-02-22 10:47:36 +0000 |
commit | 7d71f6641fcb660de0f003e2c028b464d7116ca1 (patch) | |
tree | eab821617b26ce34b0dc834f2e0f11cfee67c2a0 /src/python/m5/util/multidict.py | |
parent | 8e5d168332c4ac3851aee4f815cff0b62b37cc40 (diff) | |
download | gem5-7d71f6641fcb660de0f003e2c028b464d7116ca1.tar.xz |
python: Make iterator handling Python 3 compatible
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 <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/15992
Reviewed-by: Juha Jäykkä <juha.jaykka@arm.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Diffstat (limited to 'src/python/m5/util/multidict.py')
-rw-r--r-- | src/python/m5/util/multidict.py | 21 |
1 files changed, 6 insertions, 15 deletions
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') |