a h wrote: > > I have witten C code which call a function defined in python, passing > an structure, but couldn't know how to pass c structure into a python > function(data conversion) and how to write python script > function which takes an c structure and fill value into it (commented > portion) > > I have looked at struct module but couldn't understand that how it > works for below. > > typedef struct employee > { > char emp_name[10]; > int emp_ID; > }emp;
I would pass the struct as a string of 14 bytes, then use emp_name, emp_ID = struct.unpack( '=10cI', incoming ) class employee: def __init__( self, name, id ): self.name = name self.id = id def to_file( self, f ): f.write( struct,pack( '=10cI', self.name, self.id ) def from_string( self, s ): self.name, self.id = struct.unpack( '=10cI', s ) f = open( 'testing', 'w' ) e = employee( 'Testing', 923 ) e.to_file( f ) -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32