Deducing classes???

Arinte shouldbe at message.com
Thu Dec 2 12:14:17 EST 1999


Questions peppered in the comments of the code.
I have these python classes.

class PossDevice:

 def __init__(self, devname, hand, classname):
  self.devname = devname   <---- Are these private to the class?
  self.handle = hand <---- Are these private to the class?
  self.classname = classname  <---- Are these private to the class?

 def IOCTL(self, command, dargs):
  poss.IOCtl(self.devname,dargs) #make this pass the ioctl command as an
PossArg with a special name

class PossArg:
 def __init__(self,argname, argvalue):
  self.argname = argname
  self.argvalue = argvalue

 def getValue(self):
  return self.argvalue
 def getName(self):
  return self.argname

devlist = [10,9]
devlist[0] = PossDevice.PossArg("check",10)
devlist[1] = PossDevice.PossArg("boo","testing strings")
#face = devlist[0]
print devlist[0].getName()
print devlist[0].getValue()
ooo = PossDevice.PossDevice(10,"devlist",79)
ooo.IOCTL(10,devlist)
----------------------------------------------------------------------------
----------------------------------------
Then I have this c/c++ code talking with it.

PyObject *IOCtl(PyObject* self,PyObject* args){
 int rets(0);
 PosArgEx* p=createArgs(PyObject_GetItem(args, Py_BuildValue("i",1) ));
 delete p;
 return Py_BuildValue("i",rets);
}

PosArgEx* createArgs(PyObject* pobj)
{
 int icnt(PyObject_Length(pobj));  // gives a value of 2 as expected
 if (icnt==-1)
  return NULL;
 PosArgEx* pargs =  new PosArgEx(icnt);
 PyObject *tobj,*vobj,*nobj,*dummy;
 char *typestr;
 char* namestr;
 char* vstr;
 long val(0);
 for(int idx=0;idx<icnt;++idx){
  tobj = PyObject_GetItem(pobj, Py_BuildValue("i",idx) );  // returns a
variable of PyInstance_Type as expected
  vobj = PyObject_CallMethod(tobj,"getValue",NULL);  // returns a var of
PyInt_Type as expected
  if(vobj==NULL){
   // error
  }
  dummy = PyObject_Type(vobj);  // Here's where it gets screwy.  Type is
PyInt_Type
  PyArg_ParseTuple(vobj, "i", &val);  // doesn't give me an integer value???
  nobj = PyObject_CallMethod(tobj,"getName",NULL); // returns a var of type
PyChar

  if (!PyArg_ParseTuple(nobj, "s", &namestr)){    // namestr is set to junk.
   // error
  }

trncmp(typestr,"string",6)==0){  
   if (!PyArg_ParseTuple(vobj, "s", &vstr)){
    // error
   }
... stuff not relevant to the problem, because it never gets this far...
}

I traced it using VC++ 6, that is how I know the types for some of the variables.  Why can't I get the values from the functions?  Should I try to access the member variables from my C++ code?  Does that mean they can't be private anymore?

thanks











More information about the Python-list mailing list