Python で enum のような列挙型
Python には constant な定数という概念がない。(immutable はある)
そこで、C言語の enum のようなことをどのように実現するか調べてみた。
1 2 3 4 5 6 7 | >>> class Numbers: Zero, One, Two, Three, Four = range ( 5 ) >>> Numbers.Zero 0 >>> Numbers.Three 3 |
So cool!
参考:
http://www.velocityreviews.com/forums/t322211-enum-in-python.html
http://sla-tmp.blogspot.com/2010/10/pythonenum.html
0 件のコメント:
コメントを投稿