Am 25.02.12 21:35, schrieb Rick Johnson: > On Feb 25, 11:54 am, MRAB <pyt...@mrabarnett.plus.com> wrote: >> [...] >> That should be: >> if maxlength is not None and len(string) <= maxlength: > > Using "imaginary" infinity values defiles the intuitive nature of your > code. What is more intuitive? > > def confine_length(string, maxlength=INFINITY): > if string.length < maxlength: > do_something() > > def confine_length(string, maxlength=None): > if maxlength is not None and len(string) <= maxlength: > do_something()
I just had a closer look at it. It seems to be more complicated than i thougth: You will have to write def confine_length(string, maxlength=None): if maxlength: # maxlength exists, comparison possible if len(string) <= maxlength: do_something() else: # maxlength does not exist, so always do something do_something() you migth also write def confine_length(str, maxlength=None): do_it = (len(str) <= maxlength) if maxlength else True if do_it: do_something() but it really does not look intuitive. Hmm. My idea was that None is a perfect Value for infinity since there is no infinitely large number. But as i see it, you must have two comparisons then. Maybe someone has a better idea? Wolfgang -- http://mail.python.org/mailman/listinfo/python-list