[Python-ideas] Callable Enum values
Chris Barker
chris.barker at noaa.gov
Fri Apr 21 15:46:15 EDT 2017
OT, but...
You have to use the complete module name? Instead of `from callable_enum
> import Enum, Value`? Ouch.
yes, but:
"""
Use from x import y as z if two modules named y are to be imported or if y is
an inconveniently long name.
"""
(https://google.github.io/styleguide/pyguide.html?showone=Imports#Imports)
So you can rename it if it's long:
import callable_enum as ce
class Greeting(callable_enum.Enum):
HELLO = ce.Value(_greet_hello)
GOODBYE = ce.Value(_greet_goodbye)
TO_PYTHON_IDEAS =ce.Value(_welcome_to_python_ideas)
not too bad, and a pattern that has been pretty universally adopted by,
e.g., numpy:
import numpy as np.
I'm still on the fence for modules that I'm only using a couple names from
though...
-CHB
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170421/246261c3/attachment.html>
More information about the Python-ideas
mailing list