[Tutor] run with default value if input not given
steve at pearwood.info
Mon Oct 29 08:37:52 CET 2012
On Mon, Oct 29, 2012 at 11:28:05AM +0500, Saad Javed wrote:
> I've come up with this:
> x = sys.argv
> except IndexError:
> It works but seems hackish.
There's no need to look up sys.argv twice, nor any need to write
main(x) in both blocks. You can do each once only:
# Always use the minimum code needed inside a try block.
x = sys.argv
x = "some default value"
Here's yet another way:
args = sys.argv + ["some default value"]
More information about the Tutor