enum
Cousin Stanley
HooDunnit at didly42KahZidly.net
Tue Oct 31 13:39:38 EDT 2017
ast wrote:
> https://docs.python.org/3.5/library/enum.html#planet
>
> Documentation says that the value of the enum
> members will be passed to this method.
>
> But in that case __init__ waits for two arguments, mass
> and radius, while enum member's value is a tuple.
>
> It seems that there is a tuple unpacking, but it is
> not documented, that's not clear
> ....
I added the following code to your example
to unpack planet.value into mass and radius
after first importing Enum ....
from enum import Enum
def test_01() :
print( '\n planet mass radius gravity \n' )
for planet in Planet :
mass , radius = planet.value
print( ' {:8s} {:9.4E} {:9.4E} {:9.4E} '.format( planet.name , mass , radius ,
planet.surface_gravity ) )
if __name__ == '__main__' :
test_01()
A working copy ....
http://csphx.net/python/planets_enum.txt
--
Stanley C. Kitching
Human Being
Phoenix, Arizona
More information about the Python-list
mailing list