Unix programmers and Idle

Dale Amon amon at vnl.com
Sat Apr 4 02:36:33 CEST 2009

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!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20090404/d722e825/attachment.sig>

More information about the Python-list mailing list