Hi all,

I have got several python scripts and I need to run them in one shot.
So I assume that in a .py file I can give statements ./file1.py
./file2.py
./file3.py
etc to run multiple scripts.
I am defining global variables in a config.py file and these will be shared by the 3 scripts(file1.py, file2.py and file3.py).
Now I need to use a parameter in each of the scripts : INITIAL_SOCKET_NUMBER = 10000.
So this needs to be part of the config file.
Now in the file1.py, I need to create 20 sockets. So INITIAL_SCOCKET_NUMBER + 20 would be final socket number. I then want to pass this value to the file2.py. file2.py should create and use 20 more sockets and it should pass INITIAL_SOCKET_NUMBER + 20 + 20 to file3.py.... and so on...
Could any one please tell me how to do this?

Regards,
Prashanth

Try making the INITIAL_SOCKET_NUMBER a static member of some class in your config file. That way, any changes to it should be preserved along with the class definition, no matter how many files its imported in.

# config.py
class Global(object):
    INIT_SOCK_NUM = 10000

# file1.py
from config import Global
def work():
    # use Global.INIT_SOCK_NUM
    Global.INIT_SOCK_NUM += 20

# file2.py
from config import Global
def work():
    # use Global.INIT_SOCK_NUM
    Global.INIT_SOCK_NUM += 20

# main.py
import file1
import file2
from config import Global

file1.work()
file2.work()
print Global.INIT_SOCK_NUM

Hope this helps.

Hi thanks for the reply.
I used your solution and it solved my problems.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.