Comments on my first script?

bruno.desthuilliers at gmail.com bruno.desthuilliers at gmail.com
Sat Jun 14 16:13:47 EDT 2008


On 13 juin, 13:39, "D'Arcy J.M. Cain" <da... at druid.net> wrote:
> On Fri, 13 Jun 2008 10:19:38 +0200
>
> Bruno Desthuilliers <bruno.42.desthuilli... at websiteburo.invalid> wrote:
> > Ok, since you asked for it, let's go:
>
> Good commentary.  One small improvement:
>
> > REC_CLEANERS = {
> >     '.net' : clean_net,
> >     '.com' : clean_com,
> >     '.tv'  : clean_net,
> >     '.uk'  : clean_co_uk,
> >     (etc...)
> > }

FWIW, the keys should not start with a '.'. My fault...

> > for domain in rec:
> >     # code here
> >     ext = domain.rsplit('.', 1)[1]
> >     cleaner = REC_CLEANERS.get(ext, None)
> >     if cleaner:
> >         rec = cleaner(rec)
>
> How about this?
>
> for domain in rec:
>     # code here
>     ext = domain.rsplit('.', 1)[1]
>     rec = REC_CLEANERS.get(ext, lambda x: x)

Depends on if you want to know if there's a match or if you just don't
care.

> I suppose you could predefine the default function as well.

Yeps. That's usually what I do when I end up using the above variant
more than once in a module.




More information about the Python-list mailing list