inheritance from xmlrpclib.ServerProxy in python
为什么这个代码不起作用?
1 2 3 4 5 6 7 8 9 | #!/usr/bin/python2 from xmlrpclib import ServerProxy class ServerProxy1(ServerProxy): def __str__(self): return str(self.__host) proxy = ServerProxy1("http://workshop:58846/") print proxy |
原产地:
1 2 3 4 5 6 7 | def __repr__(self): return ( "" % (self.__host, self.__handler) ) __str__ = __repr__ |
结果:
1 2 3 | File"/usr/lib/python2.7/xmlrpclib.py", line 793, in close raise Fault(**self._stack[0]) xmlrpclib.Fault: :method"_ServerProxy1__host.__str__" is not supported'> |
答案就藏在这个帖子里
类
当用双下划线前缀编写代码时,您可以像这样访问它
1 2 3 | class ServerProxy1(ServerProxy): def __str__(self): return str(self._ServerProxy__host) |
…但是,如果未来版本的