PyWart: Language missing maximum constant of numeric types!

Wolfgang Meiners WolfgangMeiners01 at web.de
Sun Feb 26 08:38:37 EST 2012


Am 26.02.12 14:16, schrieb Wolfgang Meiners:
> 
> I just had a closer look at it. It seems to be more complicated than i
> thougth: You will have to write

Obviously not close enough, as i just learned.

> 
> def confine_length(string, maxlength=None):
>     if maxlength: # maxlength exists, comparison possible
      if maxlength is not None: # 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
      do_it = (len(str) <= maxlength) if maxlength is not None else True
>     if do_it:
>         do_something()
> 

I hope, it's correct now.
Wolfgang



More information about the Python-list mailing list