0

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

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by prashanth s j
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.