The hardest problem in computer science...
Ethan Furman
ethan at stoneleaf.us
Tue Jan 10 21:07:34 EST 2017
On 01/10/2017 08:06 AM, Paul Moore wrote:
> On Tuesday, 10 January 2017 15:47:20 UTC, Paul Moore wrote:
>> On Saturday, 7 January 2017 19:14:43 UTC, Ethan Furman wrote:
>>> Ya know, that looks an /awful/ lot like a collection! Maybe even an Enum? ;)
>>>
>>> -- 8< -------------------------------------------------------
>>> from aenum import Enum # note the 'a' before the 'enum' :)
>>>
>>> class Theme(Enum, init='v vr llc'):
>>> DEFAULT = "│ ", "├─ ", "└─ "
>>> BOLD = "┃ ", "┣━ ", "┗━ "
>>> ASCII = "| ", "|- ", "+- "
>>>
>>> def draw_tree(tree, theme=Theme.DEFAULT):
>>> print(theme.v)
>>> print(theme.vr)
>>> print(theme.v)
>>> print(theme.llc)
>>>
>>> draw_tree(None)
>>
>> I noted the "a" before enum :-)
>>
>> Is the implication that this form (a sort of combined namedtuple/enum)
>> *isn't* possible with the stdlib enum? But rather that it's specific
>> to your aenum module?
It's possible with the stdlib version, and a built-in convenience with aenum.
>> I don't see any documentation for the "init"
>> parameter in either version, so I'm a little puzzled.
It's in the docs for aenum, which you will get with the source download. I need to figure out how to get them included in the wheels. :(
>> The capability seems neat, although (as is probably obvious) the way you
>> declare it seems a little confusing to me.
Yes, it is possible to pass keyword arguments in a class header, although (as far as I know) very few make use of this.
> Anyway, it's a neat feature - I'd not really looked beyond the surface of
> the new enum module, looks like I missed some good stuff :-)
Lot's of good stuff in the stdlib, but who has time to learn it all? :(
--
~Ethan~
More information about the Python-list
mailing list