On Fri, 28 May 2010 07:42:30 am Alex Hall wrote: > Thanks for all the explanations, everyone. This does make sense, and > I am now using the > if(arg==None): arg=self.arg > idea. It only adds a couple lines, and is, if anything, more explicit > than what I was doing before.
You should use "if arg is None" rather than an equality test. In this case, you are using None as a sentinel value. That is, you want your test to pass only if you actually receive None as an argument, not merely something that is equal to None. Using "arg is None" as the test clearly indicates your intention: The value None, and no other value, is the sentinel triggering special behaviour while the equality test is potentially subject to false positives, e.g. if somebody calls your code but passes it something like this: class EqualsEverything: def __eq__(self, other): return True instead of None. -- Steven D'Aprano _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor