2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-27 15:18:06 +00:00

python: Use getattr() and setattr() instead of __dict__.

This leaves one use of __dict__ used for iterating through attributes.
I could use dir() instead, but I was put off by this note in its
documentation in the Python Library Reference:

    Because dir() is supplied primarily as a convenience for use at an
    interactive prompt, it tries to supply an interesting set of names more
    than it tries to supply a rigorously or consistently defined set of names,
    and its detailed behavior may change across releases.  For example,
    metaclass attributes are not in the result list when the argument is a
    class.

Suggested-by: Reid Price <reid@nicira.com>
This commit is contained in:
Ben Pfaff
2011-08-22 14:31:18 -07:00
parent 57d6a4c71b
commit 523a3bc773
3 changed files with 5 additions and 6 deletions

View File

@@ -18,7 +18,7 @@ import signal
def _signal_status_msg(type, signr):
s = "%s by signal %d" % (type, signr)
for name in signal.__dict__:
if name.startswith("SIG") and signal.__dict__[name] == signr:
if name.startswith("SIG") and getattr(signal, name) == signr:
return "%s (%s)" % (s, name)
return s