the python idiom for the main entry point:
if __name__ == '__main__':
main()
replace main()
by whatever function should go first ...
(more on if name ...
: http://effbot.org/pyfaq/tutor-what-is-if-name-main-for.htm)
if you want to specify the function to run via command line argument, just check these arguments, either manually or via some helpers, e.g. http://docs.python.org/library/optparse.html, then branch of to the desired function.
If you don't want stuff like this:
if options.function_to_call == 'mydesiredfunction':
mydesiredfunction()
you can take advantage of getattr
.
And finally, another 'generic' approach using globals
(exception handling excluded):
$ cat 1933407.py
#!/usr/bin/env python
# coding: utf-8
import sys
def first():
print '1 of 9'
def second():
print '2 of 9'
def seventh():
print '7 of 9'
if __name__ == '__main__':
globals()[sys.argv[1]]()
Meanwhile at the command line ...
$ python 1933407.py second
2 of 9