IDL unions map to Python classes with two attributes, the discriminant d, and the value v. The constructor of the class expects the discriminant and value as parameters (in that order).
There are three possible states that a union can be in:
e.g. considering each possible state in turn:
module Example1 { union MyUnion switch(boolean) { true: string s; false: long n; };
>>> import Example1 >>> u = Example1.MyUnion(CORBA.TRUE, "Weh Hey") >>> u.d 1 >>> u.v `WeyHey' >>> u = Example1.MyUnion(CORBA.FALSE, 123) >>> u.d 0 >>> u.v 123 >>>
module Example2 { union MyUnion switch(boolean) { true: string s; default: long n; };
>>> import Example2 >>> u = Example2MyUnion(CORBA.FALSE, 123) >>> u.d 0 >>> u.v 123 >>>
module Example3 { union MyUnion switch(boolean) { true: string s; };
>>> import Example3 >>> u = Example.MyUnion(CORBA.FALSE, None) >>> u.d 0 >>> u.v None >>>