In other words, I just needed a way to identify whether the argument passed to my wrapper was one of two reserved values I was using to signal special behavior as opposed to the actual hardware profile ID. In addition, it would be great if I could attach python doc-strings to the signal values to document what they mean and what they are used for.
I'm sure my solution is less clever than most, but I used classes as the signal values. Since classes are objects in python, I don't need to actually instantiate them -- I just use the class objects themselves as the signals. As an example:
class AllWidgets(object):
"""Placeholder for indicating action applies for all widgets
"""
class CurrentWidget(object):
"""Placeholder for indicating action is applied for just
the currently selected widget
"""
def ApplyFlavor(flavor, widget=CurrentWidget):
if widget is CurrentWidget:
# Code that flavors the "current widget".
....
elif widget is AllWidgets:
# Code that flavors all widgets.
....
else:
# Code that flavors just the widget specified.
....
1 comment:
Yep :)
This happens to me sometimes when I have a function that takes a value that might be None or might be a string. I want to provide a default that means N/A, but None is a valid value. Hence, I need a "special" None. I do the same thing--I create a class called ArgNotApplicable or something like that.
Post a Comment