Passing a string with multiple arguments

I am new to python. I am using python 3.1.2 I have to communicate with the xml-rpc server through my code. From my code, I call client.py, which in turn connects to the server to get comment lists from the server.

Work code:

class xmlrpc:
    def connect(self, webaddr):
        self.server = ServerProxy(webaddr)

Method List: -

my_list = self.server.tests.getTests()

the above method works, but while I have a limitation to set tests.getTests()to one cmd_str, as shown below

my_list = self.server.cmd_str 

in this case it is cmd_strsent to client.py as the string itself, and not as another. Can someone help me how to do this?

+3
source share
2 answers

, , , . ?

class Server(object): 
    def isRunning(self): 
        print("you are inside the isRunning")

my_server = Server()
cmd_str = "isRunning"
my_function = my_server.__getattribute__(cmd_str)
my_function()

isRunning

, Server object, isRunning self, python, . my_server.__getattribute__ my_server.isRunning, .

- :

function_map = {
    'check_if_running': my_server.isRunning
}
cmd_str = 'check_if_running'
my_function = function_map[cmd_str]
my_function()

, ( python like_this, likeThis)

+1

, , , .

getattr, , .

:

cmdStr = "isRunning" 
func = getattr(Server, cmdStr)
test = func()
0

All Articles