Forums

Cast an enum, or acquire its value?

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Cast an enum, or acquire its value?

Postby TheMouster » Tue Mar 07, 2017 9:17 am

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
TheMouster
 
Posts: 4

Re: Cast an enum, or acquire its value?

Postby Charles » Tue Mar 07, 2017 11:51 am

Use type casting:
print someEnum to int
# general form of type cast expression:
<expression> to <type>
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Cast an enum, or acquire its value?

Postby TheMouster » Tue Mar 07, 2017 3:35 pm

Thanks Charles!
TheMouster
 
Posts: 4

Re: Cast an enum, or acquire its value?

Postby TheMouster » Tue Mar 07, 2017 3:51 pm

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 :-)
TheMouster
 
Posts: 4

Re: Cast an enum, or acquire its value?

Postby Charles » Fri Mar 10, 2017 3:12 pm

Thanks!
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 18 guests