diff options
| author | Ben Pfaff <blp@nicira.com> | 2011-08-23 14:43:54 -0700 |
|---|---|---|
| committer | Ben Pfaff <blp@nicira.com> | 2011-08-24 12:06:53 -0700 |
| commit | 367da738332b88425ca3e8599aa349f567f69b91 (patch) | |
| tree | 65ebc9e044f1f2a244d4346904c04836026b3a4a /python/ovs/json.py | |
| parent | 8ba31bf16d03c449fbf40ec00d9a816b4ec05018 (diff) | |
| download | openvswitch-367da738332b88425ca3e8599aa349f567f69b91.tar.gz | |
python: Use enumerate() builtin function to simplify counted iteration.
Suggested-by: Reid Price <reid@nicira.com>
Diffstat (limited to 'python/ovs/json.py')
| -rw-r--r-- | python/ovs/json.py | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/python/ovs/json.py b/python/ovs/json.py index 97ff1bbdf..5e7d8fab9 100644 --- a/python/ovs/json.py +++ b/python/ovs/json.py @@ -51,22 +51,18 @@ def to_stream(obj, stream, pretty=False, sort_keys=True): items = sorted(obj.items()) else: items = obj.iteritems() - i = 0 - for key, value in items: + for i, (key, value) in enumerate(items): if i > 0: stream.write(u",") - i += 1 __dump_string(stream, unicode(key)) stream.write(u":") to_stream(value, stream, pretty, sort_keys) stream.write(u"}") elif type(obj) in (list, tuple): stream.write(u"[") - i = 0 - for value in obj: + for i, value in enumerate(obj): if i > 0: stream.write(u",") - i += 1 to_stream(value, stream, pretty, sort_keys) stream.write(u"]") else: |
