Python datastructure -> Corba IDL

Martin von Loewis loewis at informatik.hu-berlin.de
Mon Feb 21 10:52:40 EST 2000


sascha at bespin.bespin.escape.de (Sascha Matzke) writes:

> >	struct DictEntry
> >	{
> >	   string key;
> >	   any data;	// I'm not sure what you're storing here...
> >	};
> >
> >	typedef sequence<DictEntry> Dictionary;
> >	typedef sequence<Dictionary> DictionaryList;
> >
> >	struct MyStruct
> >	{
> >	   DictionaryList	list_of_dic;
> >	   long			integer;
> >	};
> 
> And how do I represent this thing in python... I can't simply return the
> datastructure above ([{},{},...],0)....

You'd have to follow the language mapping, which would be

   MyStruct([[],[],...],0)

in this case, or

   MyStruct([[DictEntry("foo",aval)],[]],0)

in the case of ([{"foo",aval},{}],0). If you really need arbitrary
value types for the dictionary, you'd need to create it using the Any
interface, i.e.

   aval = CORBA.Any(CORBA.TC_long,42)

If you go for IDL structures, I'd really recommend to declare a more
specific type for the dictionary values.

If you are using ILU, you may consider activating the ILU extension,
where ILU would accept Python dictionaries for the above Dictionary
type: With this extension, ILU maps sequences of two-field structures
to dictionaries, if the field names are key and <?>.

Regards,
Martin




More information about the Python-list mailing list