registering objects?
Lewis Bergman
lbergman at abi.tconline.net
Mon Jan 7 07:12:34 EST 2002
I was so clueless here I didn't even know where to look in the documentation.
This is my first python program and the object oriented stuff is getting me I
think.
The situation is this:
I have a couple of classes that are used with SimpleXMLRPCServer.
I need to use it's register_function() method to enable the use of the
imported classes methods.
I could just run down the whole list with a bunch of
register_function(class.method) statements but I was hoping to loop through
them. But, either I cannot do it or I am so daft I can't figure out the
correct way to do it.
Here is the offending code:
server = SimpleXMLRPCServer(("localhost", 8000))
# instantiate classes
NixUser = NixUser.NixUser()
icradiusUser = icradiusUser.icradiusUser()
# a List of classes to loop through
importedClass = [NixUser, icradiusUser]
for name in importedClass:
for method in dir(name):
# only register methods that don't start with a "_"
if re.match("^[_]", method) is None:
server.register_function(name.method)
Which yeilds this error:
[root at lewis test]# ./testserver3.py
Traceback (most recent call last):
File "./testserver3.py", line 15, in ?
server.register_function(name.method)
AttributeError: NixUser instance has no attribute 'method'
Now that it tells me that it seems obvious. Of course it doesn't have a
"method" attribute. The question is this. Is it possible to do this kind of
dynamic thing or should I just code a bunch of
register_function(class.method1)
register_function(class.methodn)
type deals and forget about it.
--
Lewis Bergman
Texas Communications
4309 Maple St.
Abilene, TX 79602-8044
915-695-6962 ext 115
More information about the Python-list
mailing list