Possible Duplicate:
On localhost, how to pick a free port number?
My requirement is different from this question.
On localhost, how to pick a free port number?
I am writing a test setup of another process using python. The other process needs a port number to be passed (say as a command line parameter). I cannot hard-code some random port number because many users usually would run same test in the same box. Now, how do I select a free port in python?
Edit:
I am not creating a socket in python. I just need to pass a number to some other process as a command line argument.
From DRH's answer, I could create a dummy socket, get its port number, close it and pass to the actual process. Is there any better way to do this?