Ensure unwanted names removed in class definition

Ben Finney ben+python at benfinney.id.au
Thu Aug 13 00:55:50 CEST 2015


MRAB <python at mrabarnett.plus.com> writes:

> Have you thought about catching the NameError?

I had not, but that is obvious now you say it. Thanks.

Where there isn't a more elegant solution, I'll use that. It might not
be elegant, but it's at least clear and expressive of the intent.


Jussi Piitulainen <ei at kun.ei.invalid> writes:

> Make them an implementation detail:
>
>     plumage = [
>         (__foo__, __bar__) for (__foo__, __bar__) in feathers.items()
>         if __bar__ == "beautiful" ]

That still makes the name persist, so doesn't meet the requirements. It
also commits the further mistake of using a ‘__dunder__’ name style for
something that *isn't* a Python magic attribute.

Thanks for the attempt :-)

-- 
 \                 “Teeth extracted by the latest Methodists.” dentist |
  `\                                          advertisement, Hong Kong |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list