[RFC] use optparse for option handling
bignose+hates-spam at benfinney.id.au
Fri Jul 14 00:30:10 BST 2006
Aaron Bentley <aaron.bentley at utoronto.ca> writes:
> Ben Finney wrote:
> > If you really want to check *identity*, use 'is' and 'is
> > not'.
> I really want to check identity. I want to be able to use
> OptionParser.DEFAULT_VALUE as a special object, the same way None is
If that's truly the best way to implement the functionality, then
you'll need an object that *does* behave like None. Search for the
However, that's a bad design smell, and doesn't quite seem to address
what you're actually looking for.
> I want the test to evaluate to True if v is another object with the
> same value as OptionParser.DEFAULT_VALUE. It should only evaluate
> to False if v and OptionParser.DEFAULT_VALUE are two names for the
> same object.
Why not put that functionality in the object that holds that value,
and make it cognizant of whether the value is changed?
""" Hold a value and be aware of whether it's been changed. """
self._bar = "Bar default"
self._bar_modified = False
def _set_bar(self, value):
self._bar_modified = True
self._bar = value
bar = property(_get_bar, _set_bar)
>>> this_foo = Foo()
>>> this_foo.bar = "Ethel"
>>> this_foo.bar = "Bar default"
\ "People always ask me, 'Where were you when Kennedy was shot?' |
`\ Well, I don't have an alibi." -- Emo Philips |
More information about the bazaar