command line arguments processing: an ugly lpr wrapper

morden morden at
Mon Mar 17 01:50:19 CET 2003

I want the users of the script identify themselves with -B option
(for logging) and pass the remaining arguments to lpr.
What I came up with looks rather ugly:

next = 0
new_arg = []
for arg in sys.argv:
	if next:
		by = arg
		next = 0
		if arg == "-B":
			next = 1
# log "by" someplace
os.execv("/usr/bin/lpr", new_arg)

# should I exit(os.execv("/usr/bin/lpr", new_arg)) instead?

So, my question is:
how to make the code a bit less igly
and make it take arguments in format -Bfoo in addition to -B foo?

More information about the Python-list mailing list