[Tutor] run with default value if input not given
Steven D'Aprano
steve at pearwood.info
Mon Oct 29 08:31:49 CET 2012
Saad, please don't send HTML emails, as it destroys the essential
formatting of your code.
On Mon, Oct 29, 2012 at 11:06:14AM +0500, Saad Javed wrote:
> How can I make this program run with the default value of x if I don't
> specify an argument at the command line?
arguments = sys.argv[1:] # get the list of command line arguments
if arguments:
# There are some.
process(arguments)
else:
# There are no arguments.
do_something_else()
Or if you prefer, check that len(sys.argv) > 1.
--
Steven
More information about the Tutor
mailing list