Hi I'm building a generic editor for creating loading and saving gpb objects and am running into problems with dynamic __import__ statements. I've nailed it down to a very simple testcase. This is all with python 2.5.2 and protobuf 2.0.3 on Linux.
test.proto: message test { optional int32 x=1; } C.py: class K: def __init__(self): print "new K" >>> import test_pb2, C >>> a=getattr(test_pb2,"test") >>> a <class 'test_pb2.test'> >>> b=getattr(C,"K") >>> b <class C.K at 0xb64ceddc> Why is one of the classnames in quotes, and the other not? When I try a dynamic import I've narrowed my problem down to : #!/usr/bin/python def test(): for module,klass in [('test_pb2','test'), ('C', 'K')]: m=__import__(module) k=getattr(m, klass) print "*", m, k, type(k) print k() test() Which when run gives me the following * <module 'test_pb2' from '....gpbedit/test_pb2.pyc'> <class 'test_pb2.test'> <class 'google.protobuf.reflection.GeneratedProtocolMessageType'> new k= * <module 'C' from '...gpbedit/C.pyc'> C.K <type 'classobj'> new k= new K <C.K instance at 0xb7d2764c> When I try to create a protocol object of the 'test' type, my python script returns None. So where does this go wrong? Bart P.S. the editor is at http://github.com/bvdeenen/gpbedit/tree/master. It's still alpha quality, but it is capable of editing proto objects and generating a gui from proto files --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~----------~----~----~----~------~----~------~--~---