Page 1 of 1

Cast an enum, or acquire its value?

PostPosted: Tue Mar 07, 2017 9:17 am
by TheMouster
Hi,

How do I cast an enum to an integer a.k.a. acquire the enums value?

e.g.
enum Period
hour = 8736,
working_hour = 2080,
day = 365,
week = 52,
fortnight = 26,
month = 12,
bimonth = 6,
quarter = 4,
third = 3,
semiannual = 2,
annual = 1


How do I get the value for Period.week i.e. 52.

Thanks

Re: Cast an enum, or acquire its value?

PostPosted: Tue Mar 07, 2017 11:51 am
by Charles
Use type casting:
print someEnum to int
# general form of type cast expression:
<expression> to <type>

Re: Cast an enum, or acquire its value?

PostPosted: Tue Mar 07, 2017 3:35 pm
by TheMouster
Thanks Charles!

Re: Cast an enum, or acquire its value?

PostPosted: Tue Mar 07, 2017 3:51 pm
by TheMouster
I should have read more of the manual. I would have found what I was looking for. Sorry for taking the lazy route. BTW FYI I'm going to be giving a talk on Cobra at my local Python Django meet-up in May or June. Spreading the word a bit :-)

Re: Cast an enum, or acquire its value?

PostPosted: Fri Mar 10, 2017 3:12 pm
by Charles
Thanks!