I would like to know how to define the enum just like below I do in JAVA and C?
C:
typedef enum status{
OFFLINE = 1,
ONLINE = 2,
LOGIN =3
} STATUS_T;
OFFLINE = 1
ONLINE = 2
LOGIN = 3
You can wrap it in a class if you want STATUS_T.OFFLINE
style of access. Python is a dynamically typed language so the concept of an enum makes little sense, all you can do is have range of meaningful values you can set something to.
Apparently, an equivalent has been added in 3.4, see How can I represent an 'Enum' in Python?
Not really.
The most common idiom is to define a set of constants at the class level:
class PhonyEnum(object):
OFFLINE = 1
ONLINE = 2
LOGIN = 3
It's up to you to use them as constants:
if result == PhonyEnum.ONLINE:
do_something
Others also do the same thing at the module level rather than the class level