Archived
This forum has been archived. Please start a new discussion on GitHub.
How to do classes in Python
in Help Center
Hi
Is there an example of how to do classes in Python. I am trying to create a union using the class inheritance method. Slice compiles ok but I'm not sure how to use the classes in Python and my efforts so far fail with:
UnknownLocalException: exception ::Ice::UnknownLocalException
{
unknown = Operation.cpp:1915: Ice::MarshalException:
protocol error: error during marshaling or unmarshaling
}
Thanks
Bob
Is there an example of how to do classes in Python. I am trying to create a union using the class inheritance method. Slice compiles ok but I'm not sure how to use the classes in Python and my efforts so far fail with:
UnknownLocalException: exception ::Ice::UnknownLocalException
{
unknown = Operation.cpp:1915: Ice::MarshalException:
protocol error: error during marshaling or unmarshaling
}
Thanks
Bob
0
Comments
-
Hi Bob,
Can you post an example of your Slice definitions and describe what your code is trying to accomplish?
Regards,
Mark0 -
Hi Mark
Slice Def:
module AcornPersist
{
class UnionDiscriminator {
};
class MemberInt extends UnionDiscriminator {
int i;
};
class MemberFloat extends UnionDiscriminator {
float f;
};
class MemberString extends UnionDiscriminator {
string s;
};
interface Persist
{
void put(string category, string key, string value);
string get(string category, string key);
void putTyped(string category, string key, UnionDiscriminator value);
UnionDiscriminator getTyped(string category, string key);
void save();
};
};
This is just a simple test I was trying. I have a persistence service that can accept and return name/value pairs. At the moment I have them all as strings (which I then explicitly convert 'knowing' what type I expect) but wanted to 'type' them. I added the putTyped() and getTyped() methods so my get and put code could be generic but can't figure how to use the classes in Python.
Bob0 -
Hi,
In a client, you would use a class like this:persist = AcornPersist.PersistPrx.checkedCast("...") s = AcornPersist.MemberString("the string") persist.putTyped("cat", "key", s)
In a server, like so:class PersistI(AcornPersist.Persist): def putTyped(self, cat, key, val): s = None if isinstance(val, AcornPersist.MemberString): s = val.s elif isinstance(val, AcornPersist.MemberInt): # etc
Does that help?
Regards,
Mark0 -
Thanks Mark, easy when you know how.
Bob0