On Mon, Mar 30, 2009 at 10:54:56PM -0700, Niklas Norrthon wrote: > I make sure my scripts are on the form: > > # imports > # global initialization (not depending on sys.argv) > def main(): > # initialization (might depend on sys.argv) > # script logic > # other functions > if __name__ == '__main__': > main() > > Then I have a trivial debug script named debug_whatever.py, which I > use as my entry point during debugging: > > # debug_whatever.py: > import sys > sys.argv[1:] = ['arg1', 'arg2', 'arg3'] > import whatever > whatever.main()
I've found this approach very useful in another way as well. I write all my programs, in whatever language, with a perldoc section at the very end of the file where it doesn't get in the way of my seeing the code, but is still at least in the same module. Due to the problems of forward referencing I had not heretofore been able to use it inside the program module as it was obviously not defined when the code ran. However, with your method and with those two lines place at the very end after the perldoc documentation the code execution is always delayed until I can stuff it into __doc__ and thus have it available to print with a --man command line switch which I like to have in all my code. (I just pipe the __doc__ string through perl2man there) Works for me!
signature.asc
Description: Digital signature
-- http://mail.python.org/mailman/listinfo/python-list