Unix programmers and Idle

D

Dale Amon

I wonder if someone could point me at documentation
on how to debug some of the standard Unix type things
in Idle. I cannot seem to figure out how to set my
argument line for the program I am debugging in an Idle
window. for example:

vlmdeckcheck.py --strict --debug file.dat

There must be a way to tell it what the command line args
are for the test run but I can't find it so far.



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iD8DBQFJ0VLYZHES7UL0zXERAr+vAJ9FhD3fe6HY/Rd4/alqgb41jXy/oACfQWvQ
pyH4Cgd38KrIMVlLhN0gbb4=
=BVqw
-----END PGP SIGNATURE-----
 
N

Niklas Norrthon

I wonder if someone could point me at documentation
on how to debug some of the standard Unix type things
in Idle. I cannot seem to figure out how to set my
argument line for the program I am debugging in an Idle
window. for example:

        vlmdeckcheck.py --strict --debug file.dat

There must be a way to tell it what the command line args
are for the test run but I can't find it so far.

As others have said it isn't. This is what I do:

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()

/Niklas Norrthon
 
D

Dale Amon

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!


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iD8DBQFJ1quRZHES7UL0zXERAq85AJ9Ks0Dm/RzesS6m3Y/uHxK/sgkWfgCeOjmp
ysXdizqcuIc6MSj6iJz1ygo=
=87c3
-----END PGP SIGNATURE-----
 
D

Dale Amon

Just in case anyone else finds it useful, to be precise I use:

if opts.man:
p1 = Popen(["echo", __doc__], stdout=PIPE)
p2 = Popen(["pod2man"], stdin=p1.stdout, stdout=PIPE)
p3 = Popen(["nroff","-man"], stdin=p2.stdout, stdout=PIPE)
output = p3.communicate()[0]
print output

inside the def main().

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iD8DBQFJ1q5wZHES7UL0zXERAiQuAJ9IFGHKvl23HOUlwECrN41F2DsQsgCfXIK9
sxmi6edPOzq98jKgwvjmPtg=
=yNSk
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top