Question

I'm writing python. I have two different python file (client_side.py, server_side.py) call

both script function. After running these script, i got this error.

'module' object has no attribute 'server_order' error

1. Server_side.py

#!/usr/bin/python
import client_side

username = "xxxxxx"
password = "123"
filename = "dfsdf.txt"
client_side.client(username,password,filename)

def server_order():
    print "server side is running."
    return 

2. client_side.py

#!/usr/bin/python

def client(a,b,c):
    print "client side function processing.."
    client_order()
    if __name__ == '__client__':
        client()
        return 

def client_order():
    import server_side
    server_side.server_order()
    return

No correct solution

OTHER TIPS

The problem is the order you are defining the functions. You must define the functions before you import them, try this:

#!/usr/bin/python
import client_side

username = "xxxxxx"
password = "123"
filename = "dfsdf.txt"

def server_order():
    print "server side is running."
    return 

client_side.client(username,password,filename)

and

#!/usr/bin/python

def client_order():
    import server_side
    server_side.server_order()
    return

def client(a,b,c):
    print "client side function processing.."
    client_order()
    if __name__ == '__client__':
        client()
        return 

Your initial problem was that client_side.client() was being called before you defined server_order(). Therefore when client_side.client() tried to call it, it was not there!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top