Newbie question

G

Geirr

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
 
J

jmdeschamps

Geirr said:
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... ;-))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top