Geirr wrote: > Hi, ive just started playing around with python and wondered if someone > could poing me in the right way here. > > > I have a xmlrpc server simple script: > > Server script: > import SimpleXMLRPCServer > class tpo: > > def retTPOXML(): > theFile=open('tpo.xml') > try: > self.strXML = theFile.read() > return self.strXML > finally: > theFile.close() > > tpo_object = tpo() > server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost",8888)) > server.register_instance(tpo_object) > > print "Listening on port 8888" > server.serve_forever() > > and im trying to print the return value with any luck > > Client Code: > import xmlrpclib > server = xmlrpclib.ServerProxy("http://localhost:8888") > current = server.retTPOXML > print current > > > Any comment would be appriciated
First: in python, class definitions require that you explicitly refer to the instance, such as self.myMethod(). In *self.strXML* the word *self* is a variable, it should be part of the method parameter list such as *def retTPOXML(self):*. The first parameter of methods (functions in classes) refers to the instance that is created. (BTW, it could be anything else than *self*, which is pure convention) Second: In the client, your not using the method you're refering to it (methods are yet another sort of objects), yu need the parenthesis such as *current = server.retTPOXML()* Notice that on calling the method the object is on the left side of the dot, and that is the object instance that will be adequated to the *self* in the class definition. but you should also read the tutorial. (others may propose things otherwise (better versed in the theory at work behind the scene... ;-)) -- http://mail.python.org/mailman/listinfo/python-list